You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2007/07/10 23:44:32 UTC

Clone problem? Difference in behavior between 1.2 and 1.3

Working on the Book I found a difference between 1.2 and 1.3:

In the following setup if you click on the 'link' a couple of times,
you see that the list in the session grows, and that it is reflected
in each page render.

Now, press the back button and continue clicking on the link. You will
see that the page remains static from that moment on. This was not a
problem in 1.2 because the HttpSessionStore is the only way of storing
the pages for back button behavior. However, in 1.3 the 2nd level
cache is the new way of storing, and this is the consequence of that
store: you get different objects between versions.

Is there anything we can do to prevent this from happening?

public class MySession extends WebSession {
    public final List<String> list = new ArrayList<String>();
}

public class FooPage extends WebPage {
    public FooPage() {
        add(new ListView("foo", MySession.get().list){
            protected void populateItem(ListItem item) {
                item.add(new Label("text", item.getModelObject()));
            }
        });
        add(new Link("link") {
            protected void onClick() {
                MySession.get().list.add("foo " + System.currentTimeMillis());
            }
        });
    }
}

<html>
<body>
<ul>
<li wicket:id="foo"><span wicket:id="text"></span></li>
</ul>
<a href="#" wicket:id="link">Click me</a>
</body>
</html>


-- 
Wicket joins the Apache Software Foundation as Apache Wicket
Apache Wicket 1.3.0-beta2 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta2/

Re: Clone problem? Difference in behavior between 1.2 and 1.3

Posted by Johan Compagner <jc...@gmail.com>.
the problem with session data is just tricky, if you have a shopping
basket that is stored in the session object, and you add some to it,
the remove a few, then use the back button. what you now see on the
screen is the full shopping basket again, but on the serverside a
previos page is restored, so the view shows everything but the data
not, if you then remove one you have very funny behavior which you
really have to program for.

On 7/11/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > this is not really solveable by wicket itself.
> > We don't know where such a reference is comming from, so this should be
> > documented i guess
> > that if you use session data from the session object itself. You should
> > always use an extra
> > indiretion to get it
> > new Model()
> > {
> >   getObject() {Session.get().getList()}
> > }
>
> I don't see a generic solution either, but in this case I though you
> should use custom serialization of either your custom session or a
> model you use for the extra indirection.
>
> Eelco
>

Re: Clone problem? Difference in behavior between 1.2 and 1.3

Posted by Eelco Hillenius <ee...@gmail.com>.
> this is not really solveable by wicket itself.
> We don't know where such a reference is comming from, so this should be
> documented i guess
> that if you use session data from the session object itself. You should
> always use an extra
> indiretion to get it
> new Model()
> {
>   getObject() {Session.get().getList()}
> }

I don't see a generic solution either, but in this case I though you
should use custom serialization of either your custom session or a
model you use for the extra indirection.

Eelco

Re: Clone problem? Difference in behavior between 1.2 and 1.3

Posted by Johan Compagner <jc...@gmail.com>.
this is not really solveable by wicket itself.
We don't know where such a reference is comming from, so this should be
documented i guess
that if you use session data from the session object itself. You should
always use an extra
indiretion to get it
new Model()
{
  getObject() {Session.get().getList()}
}

johan


On 7/10/07, Martijn Dashorst <ma...@gmail.com> wrote:
>
> Working on the Book I found a difference between 1.2 and 1.3:
>
> In the following setup if you click on the 'link' a couple of times,
> you see that the list in the session grows, and that it is reflected
> in each page render.
>
> Now, press the back button and continue clicking on the link. You will
> see that the page remains static from that moment on. This was not a
> problem in 1.2 because the HttpSessionStore is the only way of storing
> the pages for back button behavior. However, in 1.3 the 2nd level
> cache is the new way of storing, and this is the consequence of that
> store: you get different objects between versions.
>
> Is there anything we can do to prevent this from happening?
>
> public class MySession extends WebSession {
>     public final List<String> list = new ArrayList<String>();
> }
>
> public class FooPage extends WebPage {
>     public FooPage() {
>         add(new ListView("foo", MySession.get().list){
>             protected void populateItem(ListItem item) {
>                 item.add(new Label("text", item.getModelObject()));
>             }
>         });
>         add(new Link("link") {
>             protected void onClick() {
>                 MySession.get().list.add("foo " + System.currentTimeMillis
> ());
>             }
>         });
>     }
> }
>
> <html>
> <body>
> <ul>
> <li wicket:id="foo"><span wicket:id="text"></span></li>
> </ul>
> <a href="#" wicket:id="link">Click me</a>
> </body>
> </html>
>
>
> --
> Wicket joins the Apache Software Foundation as Apache Wicket
> Apache Wicket 1.3.0-beta2 is released
> Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta2/
>