Thanks, for this additional info Martijn, i guess i am so used to
using IPageLink i sometimes forget the pitfalls for new wicket users.

The trick with the IPageLink is that it does not use the getPage
method until the link is actually clicked. And therefore your Pages
will always be constructed lazily.

But like Martijn says Link is in this case just as easy.

Maurice

On 6/26/07, Martijn Dashorst <[EMAIL PROTECTED]> wrote:
> Don't use page link!
>
> Use PageLink only if you actually know what you are doing.
>
> In this case: you should use the normal Link and set the responsepage
> in the onclick.
>
> Page1 {
>     ... counter ...
>
>     add(new Link("page2") { onclick() { setResponsePage(new
> Page2(Page1.this)); });
>     ...
> }
>
>
> Page2 {
>     private Page returnToPage;
>     public Page2(Page returnTo) {
>         this.returnToPage = returnTo;
>
>         add(new Link("page1") { onclick() { setResponsePage(returnToPage); 
> }});
>     }
> }
>
> Don't do the following, I repeat: the following is REALLY BAD:
>
> add(new PageLink("page1", new Page1()));
> add(new PageLink("page2", new Page2()));
> add(new PageLink("page3", new Page3()));
>
> Don't do that! It will exhaust your memory (you create pages upfront,
> even when they never will be used). Remember what the 'new' keyword
> does?
>
> Martijn
>
>
> On 6/26/07, Maurice Marrink <[EMAIL PROTECTED]> wrote:
> > Sure :)
> >
> > In page 1 you do add(new PageLink("start", Foo.class));
> > because you are using the class reference to your 2nd page here wicket
> > always creates a new instance, the same happens with the pagelink on
> > page2 where you go back to page 1.
> >
> > The trick is to tell wicket to use an existing page.
> > so on page 1 we could do this
> > add(new PageLink("start", new IPageLink()
> > {
> >  public Page getPage()
> > {
> >  //now we can decide which instance / constructor we use
> >  //in this case a new page is fine
> >  return new Foo(HelloWorld.this);
> > }
> > public Class getPageIdentity()
> > {
> >  return Foo.class;
> > }
> > }));
> >
> > Because we now pass the first page to the 2nd page we need to alter
> > the constructor of the 2nd page
> >
> >  public Foo(Page returnPage) {
> >                add(new Label("message", "Foo page"));
> > //this basically wraps your page in an IPageLink like we did manually on 
> > page 1
> >                Link pl = new PageLink("return", returnPage);
> >                pl.add(new AttributeAppender("class", new Model("return"), " 
> > "));
> >                add(pl);
> >        }
> >
> > And thats all there is to it.
> > And i did not even have to use a regular link like i though we would
> > have to in my previous response :)
> >
> > Maurice
> >
> > On 6/26/07, Leucht, Axel <[EMAIL PROTECTED]> wrote:
> > > Thx for the quick answer, but being a newbie can I ask you to elaborate 
> > > it a little bit more?
> > >
> > > Regards
> > >
> > > /Axel
> > >
> > >
> > > >>-----Ursprüngliche Nachricht-----
> > > >>Von: [EMAIL PROTECTED]
> > > >>[mailto:[EMAIL PROTECTED] Auftrag
> > > >>von Maurice
> > > >>Marrink
> > > >>Gesendet: Dienstag, 26. Juni 2007 11:07
> > > >>An: wicket-user@lists.sourceforge.net
> > > >>Betreff: Re: [Wicket-user] newbie-Question
> > > >>
> > > >>
> > > >>You need to pass a reference for page 1 to page 2 and then instead of
> > > >>using a pagelink on page2 to return to page1 use a regular link which
> > > >>sets the responsepage to the instance of page 1 you passed to page 2.
> > > >>
> > > >>Maurice
> > > >>
> > > >>On 6/26/07, Leucht, Axel <[EMAIL PROTECTED]> wrote:
> > > >>> Sorry if this is a dumb question and has been answered
> > > >>hundred times but I couldn't find any answer to the following
> > > >>question.
> > > >>>
> > > >>> I do have two HTML pages. Page one contains a link which
> > > >>displays the number on clicks the user executed. The second
> > > >>link jumps to page 2. Page 2 just displays a link to go back
> > > >>to page 1.
> > > >>>
> > > >>> Assume that user clicks 5 times on the ClickCounter link in
> > > >>page 1 and hence the link displays as 'This link is clicked 5
> > > >>times'. When the user the switches to page 2 and immediately
> > > >>goes back to page 1 the counter is reset to 0 and rendered as
> > > >>'This link is clicked 0 times'.
> > > >>>
> > > >>> What am I doing wrong here? I assumed that clicking on the
> > > >>return-button on page 2 goes "back" to the original session
> > > >>in page 1 ?!
> > > >>>
> > > >>> Here is my Java classes:
> > > >>> -- page 1 ---
> > > >>> public class HelloWorld extends WebPage implements Serializable {
> > > >>>         public HelloWorld() {
> > > >>>                 add(new Label("message", "Foo World!"));
> > > >>>                 add(new PageLink("start", Foo.class));
> > > >>>                 final ClickCount count1 = new ClickCount();
> > > >>>                 Link link1 = new Link("link1") {
> > > >>>                         public void onClick() {
> > > >>>                                 count1.clicks++;
> > > >>>                         }
> > > >>>                 };
> > > >>>                 link1.add(new Label("label1", new Model() {
> > > >>>                         public java.lang.Object
> > > >>getObject(Component component) {
> > > >>>                                 return
> > > >>Integer.toString(count1.clicks);
> > > >>>                                 }
> > > >>>                 }));
> > > >>>                 add(link1);
> > > >>>         }
> > > >>>
> > > >>>         class ClickCount implements Serializable {
> > > >>>                 private int clicks = 0;
> > > >>>         }
> > > >>> }
> > > >>> --- page 2 ---
> > > >>> public class Foo extends WebPage {
> > > >>>         public Foo() {
> > > >>>                 add(new Label("message", "Foo page"));
> > > >>>                 Link pl = new PageLink("return", HelloWorld.class);
> > > >>>                 pl.add(new AttributeAppender("class", new
> > > >>Model("return"), " "));
> > > >>>                 add(pl);
> > > >>>         }
> > > >>> }
> > > >>> /Axel
> > > >>>
> > > >>>
> > > >>--------------------------------------------------------------
> > > >>-----------
> > > >>> This SF.net email is sponsored by DB2 Express
> > > >>> Download DB2 Express C - the FREE version of DB2 express and take
> > > >>> control of your XML. No limits. Just data. Click to get it now.
> > > >>> http://sourceforge.net/powerbar/db2/
> > > >>> _______________________________________________
> > > >>> Wicket-user mailing list
> > > >>> Wicket-user@lists.sourceforge.net
> > > >>> https://lists.sourceforge.net/lists/listinfo/wicket-user
> > > >>>
> > > >>
> > > >>--------------------------------------------------------------
> > > >>-----------
> > > >>This SF.net email is sponsored by DB2 Express
> > > >>Download DB2 Express C - the FREE version of DB2 express and take
> > > >>control of your XML. No limits. Just data. Click to get it now.
> > > >>http://sourceforge.net/powerbar/db2/
> > > >>_______________________________________________
> > > >>Wicket-user mailing list
> > > >>Wicket-user@lists.sourceforge.net
> > > >>https://lists.sourceforge.net/lists/listinfo/wicket-user
> > > >>
> > >
> > > -------------------------------------------------------------------------
> > > This SF.net email is sponsored by DB2 Express
> > > Download DB2 Express C - the FREE version of DB2 express and take
> > > control of your XML. No limits. Just data. Click to get it now.
> > > http://sourceforge.net/powerbar/db2/
> > > _______________________________________________
> > > Wicket-user mailing list
> > > Wicket-user@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Wicket-user mailing list
> > Wicket-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
>
>
> --
> Wicket joins the Apache Software Foundation as Apache Wicket
> Join the wicket community at irc.freenode.net: ##wicket
> Wicket 1.2.6 contains a very important fix. Download Wicket now!
> http://wicketframework.org
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to