You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by xieweiguo <xi...@139.com> on 2012/06/05 02:56:28 UTC
Confusion about tapestry singleton page
Hello!
I heard that from tapepstry 5.2,all page is singleton-object.But,I write
some code in the constructor of page class like this:
//the constructor
public TestPage()
{
System.out.println("=============+++++++++++++++++++++++ constructor
run ");
}
The code will run more than once.
So,my question is: Is the page singleton? If I want to do something just
once in a page,what should I do(use synchronized?)? and, if I want a
singleton component( such as common parts of all pages),what should I do?
I am using tapestry 5.3.3.
Thanks.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Confusion-about-tapestry-singleton-page-tp5713619.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Confusion about tapestry singleton page
Posted by Arno Haase <ar...@haase-consulting.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I tried to reproduce that (being the curious person that I am ;-) ),
but the constructor of a page is called only once on my machine - just
as one would expect (Tap 5.3.3)
If you want to analyze I suggest adding
new Error().printStackTrace();
to your constructor so you can see who actually calls it.
- - Arno
Am 05.06.2012 13:47, schrieb Thiago H de Paula Figueiredo:
> On Tue, 05 Jun 2012 08:45:41 -0300, Muhammad Gelbana
> <m....@gmail.com> wrote:
>
>> I don't think this may help but tapestry modifies your
>> pages\components at the run time so it's all handled behind the
>> scenes. Although I can't explain the results of your test here !
>
> I'd guess Tapestry executes the body of the constructor at each
> request to that page.
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk/OBJcACgkQbmZsMyUPuXQVpACfSWzOJBs0glGBfWEcK814ndGt
L30An1Lg1rkSmPj8Cl8V8ZVUcC7P0SqV
=HxcB
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Confusion about tapestry singleton page
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 05 Jun 2012 08:45:41 -0300, Muhammad Gelbana <m....@gmail.com>
wrote:
> I don't think this may help but tapestry modifies your pages\components
> at the run time so it's all handled behind the scenes.
> Although I can't explain the results of your test here !
I'd guess Tapestry executes the body of the constructor at each request to
that page.
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Confusion about tapestry singleton page
Posted by Muhammad Gelbana <m....@gmail.com>.
I don't think this may help but tapestry modifies your pages\components at
the run time so it's all handled behind the scenes.
Although I can't explain the results of your test here !
On Tue, Jun 5, 2012 at 4:50 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> On Mon, 04 Jun 2012 21:56:28 -0300, xieweiguo <xi...@139.com> wrote:
>
> Hello!
>>
>
> Hi!
>
>
> I heard that from tapepstry 5.2,all page is singleton-object.But,I write
>> some code in the constructor of page class like this:
>>
>
> You should avoid using constructors in page classes.
>
>
> So,my question is: Is the page singleton?
>>
>
> Yes. The class is changed transparently by the Tapestry classloader in
> runtime so access to fields is changed to access to a per-thread map.
>
>
> If I want to do something just
>> once in a page,what should I do(use synchronized?)?
>>
>
> Your question doesn't make sense. synchronized is used when you have
> threads.
>
>
> and, if I want a
>> singleton component( such as common parts of all pages),what should I do?
>>
>
> There's no such thing as a singleton component. You need to do nothing for
> a component to be used in more than one page.
>
> --
> Thiago H. de Paula Figueiredo
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
*Regards,*
*Muhammad Gelbana
Java Developer*
Re: Confusion about tapestry singleton page
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 04 Jun 2012 21:56:28 -0300, xieweiguo <xi...@139.com> wrote:
> Hello!
Hi!
> I heard that from tapepstry 5.2,all page is singleton-object.But,I write
> some code in the constructor of page class like this:
You should avoid using constructors in page classes.
> So,my question is: Is the page singleton?
Yes. The class is changed transparently by the Tapestry classloader in
runtime so access to fields is changed to access to a per-thread map.
> If I want to do something just
> once in a page,what should I do(use synchronized?)?
Your question doesn't make sense. synchronized is used when you have
threads.
> and, if I want a
> singleton component( such as common parts of all pages),what should I do?
There's no such thing as a singleton component. You need to do nothing for
a component to be used in more than one page.
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org