Problem passing anonym-classes-models to pages
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 IModelEntity model = new LoadableDetachableModel(); // some Buttons-eventhandler public onClick() { IModelString m = new AbstractReadOnlyModelString() { 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
Re: Problem passing anonym-classes-models to pages
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 IModelEntity model = new LoadableDetachableModel(); // some Buttons-eventhandler public onClick() { IModelString m = new AbstractReadOnlyModelString() { 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
Re: Problem passing anonym-classes-models to pages
Hi Martijn, Think of the following use-case. There is reusable PersonSelectionPage which should select one person from a list. These page should be usable from some other pages which have entities which can be assigned a person to. A IModelPerson will be passed to the PersonSelectionPage, which invokes later model.setObject(Person) after successfull selection. The specialized assignment code now is contained in the setObject(Person) method. IModelPerson pm = new IModelPerson() { public void setObject() { // do something clever here } } setResponsePage( new PersonSelectionPage(pm, getPage()) ); The PersonSelectionPage also gets the return-to-page as parameter, to be able to go-back (never got this working with redirectToInterceptPage+continueToOriginalDestination) Is such a usage out of the best-practices/idea of wicket? Jens Martijn Dashorst schrieb: 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 IModelEntity model = new LoadableDetachableModel(); // some Buttons-eventhandler public onClick() { IModelString m = new AbstractReadOnlyModelString() { 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 -- dipl. inform jens zastrow phone | +49.152.04840108 mail | m...@jens-zastrow.de web | http://jens-zastrow.de xing | http://www.xing.com/profile/Jens_Zastrow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org