Don't pass IModels around, use the model values they represent. Unless
of course, you know what you are doing. For example, if you share a
Model between two pages, it actually becomes two different instances
after being passed on: one in the first page PageA (serialized with
PageA), and one in the response page PageB (serialized with PageB).
When you try to check whether PageA.getModel() == PageB.getModel()
then you'll discover that they are not the same (might be equal, but
not the same instance).

Anonymous IModels should never be passed around.

In our apps we always let each page wrap the domain classes in their
own IModel copy (for example an HibernateModel).

Martijn

On Wed, May 27, 2009 at 1:22 PM, Jens Zastrow <m...@jens-zastrow.de> wrote:
> Hi,
>
> I use a lot of "anonym-classes-models" which a want to pass to Page
> instances (no need for be bookmarkable)
>
> class HomePage() {
> // some Models here
> IModel<Entity> model = new LoadableDetachableModel();
>
> //.... some Buttons-eventhandler
> public onClick() {
>     IModel<String> m = new AbstractReadOnlyModel<String>() {
>            public String getObject() {
>                  return "hello page".
>            }
>     }
>
>     setResponsePage( new HelloPage(m) );
> }
>
> //....
> public void detach() {
>    model.detach();
> }
>
> As i discovered now, this seems not to fit conceptually.
>
> 1. using anonym model-classes <m> javac always generates a reference to to
> enclosing class-instance, here <HomePage>
> 2. during detachment of page <HelloPage> the model <m> will ne detached
> correctly (clearing transient all objects)
> 3. after detachment the page <HelloPage> is going to be serialized, which
> the effect that the reference to the page <HomePage>
>   is serialized as well, without detaching thier models.
>
> Are there any "best-practices" related to this issue?
> Maybe pushing the <HomePage> on the "page-map-stack" forking
> <setResponsePage>?
>
> Thanks
> Jens Zastrow
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to