Hi Hector,

There are a couple of different ways to write view models, and they have
different capabilities.  At some point I anticipate we'll deprecate
some/most of these... we are where we are.

What's common about all the view models is that the view model's state is
converted into the object's OID: this is visible in the URL of the object
(either in Wicket viewer or REST API).  When the view model is next
interacted with, then the framework recreates the view model from that OID,
then invokes the action/property edit.

Which state is extracted into the OID/used to rehydrate the view model
subsequenty varies by implementation:

- if your code implements ViewModel interface, then you have full control
(the viewModelInit and viewModelMemento methods are basically reciprocals
of each other)

- if your code is annotated with @ViewModel or with
@DomainObject(nature=VIEW_MODEL | EXTERNAL_ENTITY | INMEMORY_ENTITY), then
the framework will use the state of any properties of the domain object;
however collections are ignored

- if your code is annotated with @XmlRootElement, then we use JAXB to
serialize the entire object graph; in practice this means both properties
and collections, ignoring fields annotated with @XmlTransient.  Any
references to entities are converted to bookmarks, assuming that those
entities are themselves annotated
with @XmlJavaTypeAdapter(PersistentEntityAdapter.class)

Hopefully that's enough for you to figure out what's going on.  But if not,
perhaps you could post some code or, even better, create a simple example
app that demonstrates the issue.

Cheers
Dan







On 19 November 2016 at 03:14, Hector Fabio Meza <
[email protected]> wrote:

> Based on the suggestions I got after my last mail, I am now in the process
> of implementing a View Model.
> I'm basing my implementation on the ViewModels in isis-app-todoapp, and
> the YouTube videos about View Models.
>
> So far I've been able to create a View Model that shows a list of objects,
> but ran into a problem when trying to add a Filter functionality. It's
> probably due to a misunderstanding on how ViewModels work, so I'd like to
> make sure my approach is correct.
>
> I created a DTO that stores the fields I want to use as a filter, and
> annotated it with JAXB XML annotations (I think this is necessary due to
> the ViewModels using a String representation at some point).
>
> Then I created an attribute in the ViewModel of type DTO, and created an
> action "Filter" that asks the user for values for the DTO's fields and
> stores them in the ViewModel's attribute, and then returns "this".
>
> The problem appears when the getObjects method is called after reloading
> the page. I try to access the attribute of type DTO and get the values that
> "Filter" set, to show the list with only the values that meet the criteria,
> but at this point all the DTO's fields are null.
>
> TodoApp's ToDoItemsByDateRangeViewModel.java has a DateRange attribute,
> which leads me to think that ViewModels can store objects as attributes and
> use their values for processing, but in my case it seems that my FilterDTO
> is not being stored between action invocations.
>
> The DTO is initialized in the ViewModels constructor, so I'm wondering if
> after returning "this" from an action, the object is recreated at some
> point?
>
> Or maybe I'm not doing this correctly, or ViewModels are stateless, maybe
> when dealing with non persistent objects?
>
> Thank you.
> --
>
> *Hector Fabio Meza*
> *R&D Lead smartools*
> (57) 300 2254455= <%2857%29%20300%206815404>
> Skype: hectorf.meza
> www.smartools.com.co
>
>

Reply via email to