isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Benedict Jabines <jabines...@gmail.com>
Subject Re: View Model has List of domain object
Date Thu, 09 Nov 2017 22:46:32 GMT
Nice. Thanks Dan.

On 10 Nov 2017 4:01 a.m., "Dan Haywood" <dan@haywood-associates.co.uk>
wrote:

Hi Paul,

You say in your menu you add to the collection, so I'm guessing your view
model is something like:

@ViewModel
public class MyViewModel {

    private List<DomainObject> domainObjects = new ArrayList<>();
    public List<DomainObject> getDomainObjects() { return domainObjects; }
    public void setDomainObjects(List<DomainObject> domainObjects) {
this.domainObjects = domainObjects; }

   ...
}

and I guess in your menu there's code like:

List<DomainObject> domainObjects =  ... // whatever
MyViewModel vm = new MyViewModel();
vm.setDomainObjects(someDomainObjects);
return vm;

If that's the case, then the reason this fails is that @ViewModel does not
serialize out the state of collections, only properties.    The same is
true if you use @DomainObject(nature=VIEW_MODEL), or =INTERNAL_ENTITY, or
=EXTERNAL_ENTITY ... it all works the same way under the covers.

However, there is good news.  If you instead define the view model using
JAXB then the state of the collection *is* serialized out.  Note though
that the domain object will need to be annotated with
@XmlTypeAdapter(PersistentEntityAdapter.class).

For more info, see [1]

HTH
Dan

[1]
http://isis.apache.org/guides/ugfun/ugfun.html#_ugfun_
programming-model_view-models_jaxb



On Thu, 9 Nov 2017 at 17:01 Paul Benedict Jabines <jabinespbi@gmail.com>
wrote:

> Hi,
>
> I have tried to create a view model which has a property domainObjects,
> which is a List<DomainObject>. Now, in code the Menu instantiate the View
> Model and add something to the list of domain object, but when the program
> runs and I call on the method on the menu, it returns the view model but
> the List is empty.
> I look at the simple app archetype, the HomePageViewModel's getObjects()
> calls the repo and return whatever the repo returns.
>
> public List<SimpleObject> getObjects() {
>     return simpleObjectRepository.listAll();
> }
> Is it not allowed to add the collection inside Menu?
> Is there something I did not understand about the View Model?
>
>
>
> --
> - Paul
>
> <
> https://www.avast.com/sig-email?utm_medium=email&utm_
source=link&utm_campaign=sig-email&utm_content=webmail
> >
> Virus-free.
> www.avast.com
> <
> https://www.avast.com/sig-email?utm_medium=email&utm_
source=link&utm_campaign=sig-email&utm_content=webmail
> >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message