You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by 西门烧雪 Simon <se...@gmail.com> on 2010/07/07 19:03:24 UTC

Question - Does Wicket really initialize a page instance once?

I have read that "in Wicket a page is only constructed once", from
https://cwiki.apache.org/WICKET/reading-from-a-database.html

So I did an experiment with the following class.  When I press F5
twice in my browser to refresh, and I get the print out (see below)
three times.  So, is the statement "in Wicket a page is only
constructed once" correct?

public class Echo extends WebPage {

	public Echo() {
		System.out.println(this.toString());
	}

}

Print out:

[Page class = org.appfuse.web.pages.echo.Echo, id = 0, version = 0]
[Page class = org.appfuse.web.pages.echo.Echo, id = 1, version = 0]
[Page class = org.appfuse.web.pages.echo.Echo, id = 2, version = 0]

Thank you

-- 
Simon
西门烧雪

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by James Carman <ja...@carmanconsulting.com>.
For session-level stuff, store the values in the session, not a
component/page instance.

On Jul 9, 2010 8:36 AM, "Martin Makundi" <ma...@koodaripalvelut.com>
wrote:

But changes will not propagate. You might think that you are
transferring money from account A to account B but are transferring
money from account A' to account B'.... so you need to consider this
when implementing.

Ofcourse it's a dumb example nobody implements such transactions in
session memory (I hope ;)) but somebody might try similar things for
more lightweight transactions.

**
Martin

2010/7/9 James Carman <ja...@carmanconsulting.com>:

> The equals()/hashCode() should already work as expected for components
>
> On Jul 9, 2010 8:28 AM,...
> <ml...@n4.nabble.com>
<ml...@n4.nabble.com>
>

>>
>> wrote:
>
>> Also yes ;)
>>
>> 2010/7/7 James Carman <[hidden email]<
> http://user/SendEmail.j...
> <ml...@n4.nabble.com>
<ml...@n4.nabble.com>
>

>>
>> To unsubscribe from Wicket - User, click here<
> http://apache-wicket.1842946.n4.nabble.com/su...

---------------------------------------------------------------------
To unsubscribe, e-mail: users-...

Re: Question - Does Wicket really initialize a page instance once?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
But changes will not propagate. You might think that you are
transferring money from account A to account B but are transferring
money from account A' to account B'.... so you need to consider this
when implementing.

Ofcourse it's a dumb example nobody implements such transactions in
session memory (I hope ;)) but somebody might try similar things for
more lightweight transactions.

**
Martin

2010/7/9 James Carman <ja...@carmanconsulting.com>:
> The equals()/hashCode() should already work as expected for components
>
> On Jul 9, 2010 8:28 AM, "avrahamr" <av...@gmail.com> wrote:
>
>
> But a different page instance for each person or browser section is expected
> by any Java developer.
>
> What is not so much expected is that for the same person, in the same
> browser session, you can't rely on natural object identity, like Martin
> said, thanks to serialization... But you can rely on object values, so if
> you correctly implement hash and equals it should be fine.
>
> On Wed, Jul 7, 2010 at 10:48 PM, Martin Makundi [via Apache Wicket] <
> ml-node+2281423-751388596-293983@n4.nabble.com<ml...@n4.nabble.com>
> <ml...@n4.nabble.com>
>>
>> wrote:
>
>> Also yes ;)
>>
>> 2010/7/7 James Carman <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=0>>:
>>
>>
>> > 2010/7/7 Martin Makundi <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=1>>:
>
>>
>> >> But remember... not being reconstructed does not mean that you won't
>> >> have MULTIPLE INSTA...
>> > To unsubscribe, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=2>
>> > For additional commands, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=3>
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=4>
>> For additional commands, e-mail: [hidden email]<
> http://user/SendEmail.jtp?type=node&node=2281423&i=5>
>>
>>
>>
>> ------------------------------
>>  View message @
>>
> http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2281423.html
>> To start a new topic under Wicket - User, email
>> ml-node+1842947-1647783149-293983@n4.nabble.com<ml...@n4.nabble.com>
> <ml...@n4.nabble.com>
>>
>> To unsubscribe from Wicket - User, click here<
> http://apache-wicket.1842946.n4.nabble.com/subscriptions/Unsubscribe.jtp?code=YXZyYWhhbXJAZ21haWwuY29tfDE4NDI5NDd8LTEwNzY0NzQ1ODc=
>>.
>>
>>
>>
>
>
> --
> []'s
> Avraham Rosenzweig
> avrahamr@gmail.com
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2283205.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by James Carman <ja...@carmanconsulting.com>.
The equals()/hashCode() should already work as expected for components

On Jul 9, 2010 8:28 AM, "avrahamr" <av...@gmail.com> wrote:


But a different page instance for each person or browser section is expected
by any Java developer.

What is not so much expected is that for the same person, in the same
browser session, you can't rely on natural object identity, like Martin
said, thanks to serialization... But you can rely on object values, so if
you correctly implement hash and equals it should be fine.

On Wed, Jul 7, 2010 at 10:48 PM, Martin Makundi [via Apache Wicket] <
ml-node+2281423-751388596-293983@n4.nabble.com<ml...@n4.nabble.com>
<ml...@n4.nabble.com>
>
> wrote:

> Also yes ;)
>
> 2010/7/7 James Carman <[hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=0>>:
>
>
> > 2010/7/7 Martin Makundi <[hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=1>>:

>
> >> But remember... not being reconstructed does not mean that you won't
> >> have MULTIPLE INSTA...
> > To unsubscribe, e-mail: [hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=2>
> > For additional commands, e-mail: [hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=3>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=4>
> For additional commands, e-mail: [hidden email]<
http://user/SendEmail.jtp?type=node&node=2281423&i=5>
>
>
>
> ------------------------------
>  View message @
>
http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2281423.html
> To start a new topic under Wicket - User, email
> ml-node+1842947-1647783149-293983@n4.nabble.com<ml...@n4.nabble.com>
<ml...@n4.nabble.com>
>
> To unsubscribe from Wicket - User, click here<
http://apache-wicket.1842946.n4.nabble.com/subscriptions/Unsubscribe.jtp?code=YXZyYWhhbXJAZ21haWwuY29tfDE4NDI5NDd8LTEwNzY0NzQ1ODc=
>.
>
>
>


--
[]'s
Avraham Rosenzweig
avrahamr@gmail.com

--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2283205.html
Sent from the Wicket - User mailing list archive at Nabble.com.

Re: Question - Does Wicket really initialize a page instance once?

Posted by Ian Marshall <Ia...@GMail.com>.
I have solved my problem.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2286113.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by Ian Marshall <Ia...@GMail.com>.

avrahamr wrote:
> 
> But you can rely on object values, so if
> you correctly implement hash and equals it should be fine.
> 

I too have a problem with multiple calls to a WebPage constructor....

I have a bookmarkable page, a link to which can be followed from a
verification E-mail which the app has sent. Following the link results in my
page constructor being called: in it I check the parameters for correct
values and then update my persistent datastore, if appropriate.

During developer testing I find that the constructor is often called twice.

I have a basic silly question to ask: how can I use hash and equals (or any
other approach) to ensure that my parameter checking and datastore update
code is called once only?


Extract of my code
------------------
public class PageVerifyEMail extends PageBase    // extends WebPage
{
  private static final long serialVersionUID = 1L;

  private static final Logger g_logger =
Logger.getLogger(PageVerifyEMail.class.getName());

  private int g_nConstructCount = 0;

  public PageVerifyEMail(PageParameters params)
  {
    super();

    g_nConstructCount++;
    g_logger.log(Level.FINE, String.format("g_nConstructCount = %d.",
g_nConstructCount));

    //
    // Check parameters.
    // If appropriate then update the persistent datastore.
    // Set appropriate feedback text in the page's components.
    //
  }

  //
  // Add components to the page
  //
}
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2283235.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by 西门烧雪 Simon <se...@gmail.com>.
I have found only this link http://www.systemmobile.com/?p=249

and I will try find my Wicket in Action book for the terms you mentioned.

Any good links for explaining the versioned-setting and statefulness concepts?

Thanks

On Fri, Jul 9, 2010 at 8:51 AM, Wilhelmsen Tor Iver <To...@arrive.no> wrote:
>> But, I am experiencing this "not so much expected scenario" that for
>> the same person, in the same browser session, click the browser's
>> Refresh Button, or F5, a new page instance is created.  Is the latter
>> behavior expected?
>
> For bookmarkable page URLs: Yes. Look into how versioned-setting and statefulness affects this behavior, though...
>
> - Tor Iver
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Simon
西门烧雪

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


SV: Question - Does Wicket really initialize a page instance once?

Posted by Wilhelmsen Tor Iver <To...@arrive.no>.
> But, I am experiencing this "not so much expected scenario" that for
> the same person, in the same browser session, click the browser's
> Refresh Button, or F5, a new page instance is created.  Is the latter
> behavior expected?

For bookmarkable page URLs: Yes. Look into how versioned-setting and statefulness affects this behavior, though...

- Tor Iver

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by 西门烧雪 Simon <se...@gmail.com>.
I understand by doing the way Jeremy Thomerson suggests (onSubmit or
onClick), Wicket will not create a new page instance upon request.
But, I am experiencing this "not so much expected scenario" that for
the same person, in the same browser session, click the browser's
Refresh Button, or F5, a new page instance is created.  Is the latter
behavior expected?

Thanks

On Fri, Jul 9, 2010 at 8:28 AM, avrahamr <av...@gmail.com> wrote:
>
> But a different page instance for each person or browser section is expected
> by any Java developer.
>
> What is not so much expected is that for the same person, in the same
> browser session, you can't rely on natural object identity, like Martin
> said, thanks to serialization... But you can rely on object values, so if
> you correctly implement hash and equals it should be fine.
>
> On Wed, Jul 7, 2010 at 10:48 PM, Martin Makundi [via Apache Wicket] <
> ml-node+2281423-751388596-293983@n4.nabble.com<ml...@n4.nabble.com>
>> wrote:
>
>> Also yes ;)
>>
>> 2010/7/7 James Carman <[hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=0>>:
>>
>>
>> > 2010/7/7 Martin Makundi <[hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=1>>:
>>
>> >> But remember... not being reconstructed does not mean that you won't
>> >> have MULTIPLE INSTANCES of the same page.....
>> >>
>> >> ... thanks to serialization ;)) so be warned if you code something
>> >> that depends on instances.
>> >
>> > It's not just serialization.  A new page instance will be constructed
>> > for each person that hits it.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=2>
>> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=3>
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=4>
>> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=5>
>>
>>
>>
>> ------------------------------
>>  View message @
>> http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2281423.html
>> To start a new topic under Wicket - User, email
>> ml-node+1842947-1647783149-293983@n4.nabble.com<ml...@n4.nabble.com>
>> To unsubscribe from Wicket - User, click here<http://apache-wicket.1842946.n4.nabble.com/subscriptions/Unsubscribe.jtp?code=YXZyYWhhbXJAZ21haWwuY29tfDE4NDI5NDd8LTEwNzY0NzQ1ODc=>.
>>
>>
>>
>
>
> --
> []'s
> Avraham Rosenzweig
> avrahamr@gmail.com
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2283205.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>



-- 
Simon
西门烧雪

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by avrahamr <av...@gmail.com>.
But a different page instance for each person or browser section is expected
by any Java developer.

What is not so much expected is that for the same person, in the same
browser session, you can't rely on natural object identity, like Martin
said, thanks to serialization... But you can rely on object values, so if
you correctly implement hash and equals it should be fine.

On Wed, Jul 7, 2010 at 10:48 PM, Martin Makundi [via Apache Wicket] <
ml-node+2281423-751388596-293983@n4.nabble.com<ml...@n4.nabble.com>
> wrote:

> Also yes ;)
>
> 2010/7/7 James Carman <[hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=0>>:
>
>
> > 2010/7/7 Martin Makundi <[hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=1>>:
>
> >> But remember... not being reconstructed does not mean that you won't
> >> have MULTIPLE INSTANCES of the same page.....
> >>
> >> ... thanks to serialization ;)) so be warned if you code something
> >> that depends on instances.
> >
> > It's not just serialization.  A new page instance will be constructed
> > for each person that hits it.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=2>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=3>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=4>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2281423&i=5>
>
>
>
> ------------------------------
>  View message @
> http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2281423.html
> To start a new topic under Wicket - User, email
> ml-node+1842947-1647783149-293983@n4.nabble.com<ml...@n4.nabble.com>
> To unsubscribe from Wicket - User, click here<http://apache-wicket.1842946.n4.nabble.com/subscriptions/Unsubscribe.jtp?code=YXZyYWhhbXJAZ21haWwuY29tfDE4NDI5NDd8LTEwNzY0NzQ1ODc=>.
>
>
>


-- 
[]'s
Avraham Rosenzweig
avrahamr@gmail.com

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Question-Does-Wicket-really-initialize-a-page-instance-once-tp2281200p2283205.html
Sent from the Wicket - User mailing list archive at Nabble.com.

Re: Question - Does Wicket really initialize a page instance once?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Also yes ;)

2010/7/7 James Carman <ja...@carmanconsulting.com>:
> 2010/7/7 Martin Makundi <ma...@koodaripalvelut.com>:
>> But remember... not being reconstructed does not mean that you won't
>> have MULTIPLE INSTANCES of the same page.....
>>
>> ... thanks to serialization ;)) so be warned if you code something
>> that depends on instances.
>
> It's not just serialization.  A new page instance will be constructed
> for each person that hits it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by James Carman <ja...@carmanconsulting.com>.
2010/7/7 Martin Makundi <ma...@koodaripalvelut.com>:
> But remember... not being reconstructed does not mean that you won't
> have MULTIPLE INSTANCES of the same page.....
>
> ... thanks to serialization ;)) so be warned if you code something
> that depends on instances.

It's not just serialization.  A new page instance will be constructed
for each person that hits it.

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
But remember... not being reconstructed does not mean that you won't
have MULTIPLE INSTANCES of the same page.....

... thanks to serialization ;)) so be warned if you code something
that depends on instances.

**
Martin

2010/7/7 Jeremy Thomerson <je...@wickettraining.com>:
> 2010/7/7 西门烧雪 Simon <se...@gmail.com>
>
>> I have read that "in Wicket a page is only constructed once", from
>> https://cwiki.apache.org/WICKET/reading-from-a-database.html
>>
>> So I did an experiment with the following class.  When I press F5
>> twice in my browser to refresh, and I get the print out (see below)
>> three times.  So, is the statement "in Wicket a page is only
>> constructed once" correct?
>>
>> public class Echo extends WebPage {
>>
>>        public Echo() {
>>                System.out.println(this.toString());
>>        }
>>
>> }
>>
>> Print out:
>>
>> [Page class = org.appfuse.web.pages.echo.Echo, id = 0, version = 0]
>> [Page class = org.appfuse.web.pages.echo.Echo, id = 1, version = 0]
>> [Page class = org.appfuse.web.pages.echo.Echo, id = 2, version = 0]
>>
>> Thank you
>>
>> --
>> Simon
>> 西门烧雪
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> You were on a bookmarkable page.  The statement should be qualified.  Every
> time you hit a bookmarkable page, or redirect to a page via
> setResponsePage(Class) or setResponsePage(Class, PageParameters), you will
> create a page.  But, for all stateful redirects, including stateful actions
> within the page, the page is not reconstructed.
>
> Try this:
>
> add a private int counter to your page class.  Then add the following
> component and click the link:
>
> add(new Link("link") {
>  public void onClick() {
>    System.out.println("link was clicked - same instance of page");
>    System.out.println(++counter);
>  }
> });
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>

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


Re: Question - Does Wicket really initialize a page instance once?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
2010/7/7 西门烧雪 Simon <se...@gmail.com>

> I have read that "in Wicket a page is only constructed once", from
> https://cwiki.apache.org/WICKET/reading-from-a-database.html
>
> So I did an experiment with the following class.  When I press F5
> twice in my browser to refresh, and I get the print out (see below)
> three times.  So, is the statement "in Wicket a page is only
> constructed once" correct?
>
> public class Echo extends WebPage {
>
>        public Echo() {
>                System.out.println(this.toString());
>        }
>
> }
>
> Print out:
>
> [Page class = org.appfuse.web.pages.echo.Echo, id = 0, version = 0]
> [Page class = org.appfuse.web.pages.echo.Echo, id = 1, version = 0]
> [Page class = org.appfuse.web.pages.echo.Echo, id = 2, version = 0]
>
> Thank you
>
> --
> Simon
> 西门烧雪
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
You were on a bookmarkable page.  The statement should be qualified.  Every
time you hit a bookmarkable page, or redirect to a page via
setResponsePage(Class) or setResponsePage(Class, PageParameters), you will
create a page.  But, for all stateful redirects, including stateful actions
within the page, the page is not reconstructed.

Try this:

add a private int counter to your page class.  Then add the following
component and click the link:

add(new Link("link") {
  public void onClick() {
    System.out.println("link was clicked - same instance of page");
    System.out.println(++counter);
  }
});

-- 
Jeremy Thomerson
http://www.wickettraining.com