You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by Kevin Meyer - KMZ <ke...@kmz.co.za> on 2011/04/18 20:36:58 UTC
Wicket and Isis and passing domain objects...
Hi Dan, I guess this one is for you...
I'm playing around with creating a custom view using Wicket, to take
advantage of the Wicket Palette form component.
I have a simple class (Tag) which basically just extends
AbstractDomainObject and has a single String member (called
Description).
In the palette contructor, I have to pass in a IModel choicesModel.
If I use the java.util.List that is returned by allInstances, I get a "Unable
to serialize class" exception, complaining:
[class=dom.todo.Tag$$EnhancerByCGLIB$$b459b0e9] <----- field that
is not serializable
The palette is still rendered, though. I have not yet put in any handlers
to try and receive the choices list and adjust the eventual target
collection.
I wanted to ask: What do you recommend I use to hold, store, and
retrieve the collection of domain objects that are to be manipulated
using the wicket Palette component?
Should I use a collection of a simple wrapper class (that is not
persisted, etc), that represents the domain object as just an integer ID
(sequence?) and a title? I can see advantages to not passing the
"live" domain object for serialisation by Wicket. For a first pass, I will
assume that the ID is just the index of the objects in the returned
collection...
...So far this seems to work (i.e. it does not throw a "not serializable"
exception.
Regards,
Kevin
Re: Wicket and Isis and passing domain objects...
Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
> Hmm... I'd have expected instead that the EntityCollectionModel would
> already be created by the owning form, and all you need to do is make
> your new widget's ComponentFactory available available to do the rendering.
This is probably just a misunderstanding - I was using a modified
version of the claims wizard (and related classes) to hard-code
rendering of the Palette component.
> You should therefore:
> a) create a ComponentFactory, similar to [1]
> b) register that ComponentFactory, typically by adding to
> META-INF/services [2]
I'll look into this - for a more general panel solution.
Thanks,
Kevin
Re: Wicket and Isis and passing domain objects...
Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Replied too quickly..
> You should therefore:
> a) create a ComponentFactory, similar to [1]
> b) register that ComponentFactory, typically by adding to
> META-INF/services [2]
As I said, I am doing this, I think.
The extra bit that I am adding in is that I am hard-coding the wicket
Palette component - and the choices are being provided by manually
grabbing the underlying domain class (via the form's getObject() and
casting it), and fetching the collection in question.
I'll read the Isis wicket viewer documentation some more - I think I
actually want a new panel (which is used to render the ??whatever I
call this?? where-ever it appears), instead of a whole new custom
form.
Thanks,
Kevin
Re: Wicket and Isis and passing domain objects...
Posted by Dan Haywood <dk...@gmail.com>.
On 20/04/2011 19:01, Kevin Meyer - KMZ wrote:
> Right.. My grief is that I have a list of domain objects:
>
> final List<Tag> tagList = wizard.getTags();
>
> and no obvious way to create a EntityCollectionModel from it. I'm
> guessing that I should be using the original ObjectAdapter instead of
> just doing the following:
>
> ObjectAdapter objectAdapter = getModelObject();
> Object object = objectAdapter.getObject();
> ToDoWizard wizard = (ToDoWizard) object;
>
Hmm... I'd have expected instead that the EntityCollectionModel would
already be created by the owning form, and all you need to do is make
your new widget's ComponentFactory available available to do the rendering.
In a little more detail... the
EntityCollectionModel.createdParented(EntityModel, OneToManyAssociation)
is the method that needs to be called. You can see that this is called
by the two forms that we currently have that render object properties...
EntityPropertiesAndOrCollectionsPanel.PropCollForm and also
EntityTabbedPanel. But in both cases they are going to delegate to the
ComponentFactoryRegistry to get a ComponentFactory to render the model.
You should therefore:
a) create a ComponentFactory, similar to [1]
b) register that ComponentFactory, typically by adding to
META-INF/services [2]
[1]
http://incubator.apache.org/isis/viewer/wicket/docbkx/html/guide/apas03.html#sec.ClaimWizardComponentFactory
[2]
http://incubator.apache.org/isis/viewer/wicket/docbkx/html/guide/ch06.html
Let me know if that helps.
Cheers
Dan
Re: Wicket and Isis and passing domain objects...
Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
> > I have a simple class (Tag) which basically just extends
> > AbstractDomainObject and has a single String member (called
> > Description).
> >
> > In the palette contructor, I have to pass in a IModel choicesModel.
> >
> OK, so here's the scoop. I've provided a bunch of implementations of
> IModel, all of which implement Wicket's LoadableDetachableModel and so
> should "do the right thing".
You've been busy!
> The most common model to use is EntityModel, which wraps an
> ObjectAdapter (which in turn wraps up a single domain object entity).
>
> In your case, though, you should use EntityCollectionModel, which can be
> used to wrap either a standalone collection (eg returned from an action)
> or a parented action (eg Order/OrderDetail).
>
> Hopefully if you have a look at some of the existing panels and how they
> use these models, you'll get the idea.
Right.. My grief is that I have a list of domain objects:
final List<Tag> tagList = wizard.getTags();
and no obvious way to create a EntityCollectionModel from it. I'm
guessing that I should be using the original ObjectAdapter instead of
just doing the following:
ObjectAdapter objectAdapter = getModelObject();
Object object = objectAdapter.getObject();
ToDoWizard wizard = (ToDoWizard) object;
Re: Wicket and Isis and passing domain objects...
Posted by Dan Haywood <dk...@gmail.com>.
Hi Kevin,
within...
On 18/04/2011 19:36, Kevin Meyer - KMZ wrote:
> Hi Dan, I guess this one is for you...
>
> I'm playing around with creating a custom view using Wicket, to take
> advantage of the Wicket Palette form component.
>
Nice. Great that you're trying this out.
> I have a simple class (Tag) which basically just extends
> AbstractDomainObject and has a single String member (called
> Description).
>
> In the palette contructor, I have to pass in a IModel choicesModel.
>
> If I use the java.util.List that is returned by allInstances, I get a "Unable
> to serialize class" exception, complaining:
>
> [class=dom.todo.Tag$$EnhancerByCGLIB$$b459b0e9]<----- field that
> is not serializable
>
OK, so here's the scoop. I've provided a bunch of implementations of
IModel, all of which implement Wicket's LoadableDetachableModel and so
should "do the right thing".
The most common model to use is EntityModel, which wraps an
ObjectAdapter (which in turn wraps up a single domain object entity).
In your case, though, you should use EntityCollectionModel, which can be
used to wrap either a standalone collection (eg returned from an action)
or a parented action (eg Order/OrderDetail).
Hopefully if you have a look at some of the existing panels and how they
use these models, you'll get the idea.
> The palette is still rendered, though. I have not yet put in any handlers
> to try and receive the choices list and adjust the eventual target
> collection.
>
> I wanted to ask: What do you recommend I use to hold, store, and
> retrieve the collection of domain objects that are to be manipulated
> using the wicket Palette component?
the models (eg EntityModel) in
org.apache.isis.viewer.wicket.model.models; see above.
> Should I use a collection of a simple wrapper class (that is not
> persisted, etc), that represents the domain object as just an integer ID
> (sequence?) and a title? I can see advantages to not passing the
> "live" domain object for serialisation by Wicket. For a first pass, I will
> assume that the ID is just the index of the objects in the returned
> collection...
> ...So far this seems to work (i.e. it does not throw a "not serializable"
> exception.
So, as you see from the above, the wicket viewer is a little more
sophisticated than this, and (hopefully!) will work with any object or
list with not too much effort.
Cheers
Dan
> Regards,
> Kevin
>
>
>