You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by kawes <ra...@gmail.com> on 2008/12/14 21:43:07 UTC

Layout Border component problem

Hi Guys, 
I just started to use T5 and lately I have hit a problem which I cannot
resovle.

I created a Border component which contains a navigation menu.

I also created some kind of a sub-applications, let's call them MyMode1,
MyMode2, MyMode3 etc and palced pagelinks to them in Border navigation.
Then I implemented another border-like components MyMode1Border,
MyMode2Border, MyMode3Border which are wrapped by Border and contains 
navigation specific to each Mode.

Now, when a new user logs in the Border page, containing pagelinks to each
Mode, is being displayed.

Then the user chooses some Mode and starts doing some stuff.
The problem is that when another user logs in and goes to the same Mode as
the prevoius one 
he is given the same instance of the Mode so when he does some stuff on the
page too he overrides what the other guy did.

I added System.out.println to the non-argument constructors of  each page
and here is what I found out:

When I restart the server and the first user comes in, clicks login button
the following instantiations take place:

com.kawecki.wapp.components.Border@617584
[INFO] AppModule.TimingFilter Request time: 625 ms
com.kawecki.wapp.components.MyMode1Border@2d09e0
com.kawecki.wapp.components.Border@12297d7
com.kawecki.wapp.components.MyMode2Border@11d20d3
com.kawecki.wapp.components.Border@1562c67
com.kawecki.wapp.components.MyMode3Border
com.kawecki.wapp.components.Border@149249e
[INFO] AppModule.TimingFilter Request time: 594 ms

Then, when the user clicks on one of the Mode pagelinks new objects are
created just like above.
But when new user logs in no new object are created and both of them uses
the same instance of a MyMode1Border class.

I read about page pooling, onPassivate, onActivate but my problem seems to
work just opposite.
So if anybody could let me know what I do wrong I would appreciate a lot.

Hope I was clear enough
Thanks in advance 
-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21004400.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: Layout Border component problem

Posted by Olle Hallin <ol...@gmail.com>.
In 5.0.17+ you will get a runtime exception if you try to initialize a page
member in the declaration.

At least for me it works that way.

Olle


2008/12/15 kawes <ra...@gmail.com>

>
> Ok found an answer to my second question,
> some info is provided here:
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/rendering.html
>
> but still would be happy if you could answer to my first question.
>
> cheers
>
>
> kawes wrote:
> >
> > Olle,
> >
> > thanks a lot. I knew what was wrong but had no idea how to deal with
> that.
> > I am gonna check it out at home 'cause now I am at work.
> >
> > But I have some questions to the resolve you suggetsed:
> >  -  Starting with 5.0.17,  it is forbidden to have initial values on page
> > - what does it mean it is forbidden? I did not notice any repoerts during
> > runtime and no during compilantion neither.
> >
> >  - what is setupRender() method? it will be called automatically ?
> >
> > thanks again
> >
> >
> > Olle Hallin wrote:
> >>
> >> What happens is that TeacherMode is mutable, and hence leaks state
> >> between
> >> different users. You are *not* given a fresh instance on each request.
> >> Instead, instances are pooled and reused.
> >>
> >> (Starting with 5.0.17,  it is forbidden to have initial values on page
> >> member variables in order to prevent bugs like this.)
> >>
> >> One way to handle this situation is:
> >>
> >> *@Persist
> >> *private TeacherMode teacherMode;
> >>
> >> public void *setupRender()* {
> >>   if (teacherMode == null) {
> >>     teacherMode = new TeacherMode(); // This will be a private instance
> >> per
> >> session
> >>   }
> >> }
> >>
> >> HTH,
> >>
> >> Olle
> >>
> >>
> >> 2008/12/15 kawes <ra...@gmail.com>
> >>
> >>>
> >>> Hi Jonathan,
> >>>
> >>> thanks for your quick response.
> >>> As you asked I uploaded classes I hit the problem in.
> >>>
> >>> Small description: One of my sub-application is Teacher (should be able
> >>> to
> >>> provide a word in foreign language and accept user's answer checks
> >>> wheather
> >>> it is correct)
> >>>
> >>> When user logs in, clicks teacher link is redirected to AvailabaleSets
> >>> (which is wrapped by TeacherBorder).
> >>>
> >>> T5.zip file uploaded and it contains:
> >>>  - Border.java
> >>>  - Border.tml (pagelinks to all stuff provided by my app)
> >>>
> >>>  - TeacherBorder.java
> >>>  - TeacherBorder.tml (contains all links to navigate my Teacher
> >>> sub-application - i.e. TeacherMode - resposnible for 'asking question',
> >>> registering results etc)
> >>>
> >>>  - AvailableSets.java
> >>>  - AvailableSets.tml (displays available sets containg words)
> >>>
> >>>  - TeacherModePage1.java
> >>>  - TeacherModePage1.tml (lets user to choose the word's set and decide
> >>> about
> >>> the questioning mode (mingled or the sequence of words had been added
> to
> >>> the
> >>> set) )
> >>>
> >>>  - TeacherModePage2.java
> >>>  - TeacherModePage2.tml (displays questions and lets to type in
> answers)
> >>>
> >>> TeacherModePage1.java contains the following line:
> >>>  private TeacherMode teacherMode = new TeacherMode();
> >>>
> >>> I belived that when new page would be displayed (whe user clicks
> >>> TeacherMode
> >>> in TeacherBorder) a brand new TeacherMode instance would be returned
> but
> >>> is
> >>> not. And is not because all the classes are already instantiated and T5
> >>> gives them back to the user for efficiency.
> >>>
> >>> Please keep in mind this is just the beggining of the work, so not
> >>> everything is like it should be from architectural point of view (i.e.
> >>> @Persist will be replaced by onPassvate and onActivate). I just wanted
> >>> to
> >>> see how it works.
> >>>
> >>> If any more details are reqiured let me know.
> >>>
> >>> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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
> >>>
> >>>
> >>
> >>
> >> --
> >> Olle Hallin
> >> Senior Java Developer and Architect
> >> olle.hallin@crisp.se
> >> www.crisp.se
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21010909.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
>
>


-- 
Olle Hallin
Senior Java Developer and Architect
olle.hallin@crisp.se
www.crisp.se

Re: Layout Border component problem

Posted by kawes <ra...@gmail.com>.
Ok found an answer to my second question, 
some info is provided here:
http://tapestry.apache.org/tapestry5/tapestry-core/guide/rendering.html

but still would be happy if you could answer to my first question.

cheers


kawes wrote:
> 
> Olle, 
> 
> thanks a lot. I knew what was wrong but had no idea how to deal with that.
> I am gonna check it out at home 'cause now I am at work.
> 
> But I have some questions to the resolve you suggetsed:
>  -  Starting with 5.0.17,  it is forbidden to have initial values on page
> - what does it mean it is forbidden? I did not notice any repoerts during
> runtime and no during compilantion neither.
> 
>  - what is setupRender() method? it will be called automatically ?
> 
> thanks again
> 
> 
> Olle Hallin wrote:
>> 
>> What happens is that TeacherMode is mutable, and hence leaks state
>> between
>> different users. You are *not* given a fresh instance on each request.
>> Instead, instances are pooled and reused.
>> 
>> (Starting with 5.0.17,  it is forbidden to have initial values on page
>> member variables in order to prevent bugs like this.)
>> 
>> One way to handle this situation is:
>> 
>> *@Persist
>> *private TeacherMode teacherMode;
>> 
>> public void *setupRender()* {
>>   if (teacherMode == null) {
>>     teacherMode = new TeacherMode(); // This will be a private instance
>> per
>> session
>>   }
>> }
>> 
>> HTH,
>> 
>> Olle
>> 
>> 
>> 2008/12/15 kawes <ra...@gmail.com>
>> 
>>>
>>> Hi Jonathan,
>>>
>>> thanks for your quick response.
>>> As you asked I uploaded classes I hit the problem in.
>>>
>>> Small description: One of my sub-application is Teacher (should be able
>>> to
>>> provide a word in foreign language and accept user's answer checks
>>> wheather
>>> it is correct)
>>>
>>> When user logs in, clicks teacher link is redirected to AvailabaleSets
>>> (which is wrapped by TeacherBorder).
>>>
>>> T5.zip file uploaded and it contains:
>>>  - Border.java
>>>  - Border.tml (pagelinks to all stuff provided by my app)
>>>
>>>  - TeacherBorder.java
>>>  - TeacherBorder.tml (contains all links to navigate my Teacher
>>> sub-application - i.e. TeacherMode - resposnible for 'asking question',
>>> registering results etc)
>>>
>>>  - AvailableSets.java
>>>  - AvailableSets.tml (displays available sets containg words)
>>>
>>>  - TeacherModePage1.java
>>>  - TeacherModePage1.tml (lets user to choose the word's set and decide
>>> about
>>> the questioning mode (mingled or the sequence of words had been added to
>>> the
>>> set) )
>>>
>>>  - TeacherModePage2.java
>>>  - TeacherModePage2.tml (displays questions and lets to type in answers)
>>>
>>> TeacherModePage1.java contains the following line:
>>>  private TeacherMode teacherMode = new TeacherMode();
>>>
>>> I belived that when new page would be displayed (whe user clicks
>>> TeacherMode
>>> in TeacherBorder) a brand new TeacherMode instance would be returned but
>>> is
>>> not. And is not because all the classes are already instantiated and T5
>>> gives them back to the user for efficiency.
>>>
>>> Please keep in mind this is just the beggining of the work, so not
>>> everything is like it should be from architectural point of view (i.e.
>>> @Persist will be replaced by onPassvate and onActivate). I just wanted
>>> to
>>> see how it works.
>>>
>>> If any more details are reqiured let me know.
>>>
>>> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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
>>>
>>>
>> 
>> 
>> -- 
>> Olle Hallin
>> Senior Java Developer and Architect
>> olle.hallin@crisp.se
>> www.crisp.se
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21010909.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: Layout Border component problem

Posted by kawes <ra...@gmail.com>.
Olle, 

thanks a lot. I knew what was wrong but had no idea how to deal with that.
I am gonna check it out at home 'cause now I am at work.

thanks again


Olle Hallin wrote:
> 
> What happens is that TeacherMode is mutable, and hence leaks state between
> different users. You are *not* given a fresh instance on each request.
> Instead, instances are pooled and reused.
> 
> (Starting with 5.0.17,  it is forbidden to have initial values on page
> member variables in order to prevent bugs like this.)
> 
> One way to handle this situation is:
> 
> *@Persist
> *private TeacherMode teacherMode;
> 
> public void *setupRender()* {
>   if (teacherMode == null) {
>     teacherMode = new TeacherMode(); // This will be a private instance
> per
> session
>   }
> }
> 
> HTH,
> 
> Olle
> 
> 
> 2008/12/15 kawes <ra...@gmail.com>
> 
>>
>> Hi Jonathan,
>>
>> thanks for your quick response.
>> As you asked I uploaded classes I hit the problem in.
>>
>> Small description: One of my sub-application is Teacher (should be able
>> to
>> provide a word in foreign language and accept user's answer checks
>> wheather
>> it is correct)
>>
>> When user logs in, clicks teacher link is redirected to AvailabaleSets
>> (which is wrapped by TeacherBorder).
>>
>> T5.zip file uploaded and it contains:
>>  - Border.java
>>  - Border.tml (pagelinks to all stuff provided by my app)
>>
>>  - TeacherBorder.java
>>  - TeacherBorder.tml (contains all links to navigate my Teacher
>> sub-application - i.e. TeacherMode - resposnible for 'asking question',
>> registering results etc)
>>
>>  - AvailableSets.java
>>  - AvailableSets.tml (displays available sets containg words)
>>
>>  - TeacherModePage1.java
>>  - TeacherModePage1.tml (lets user to choose the word's set and decide
>> about
>> the questioning mode (mingled or the sequence of words had been added to
>> the
>> set) )
>>
>>  - TeacherModePage2.java
>>  - TeacherModePage2.tml (displays questions and lets to type in answers)
>>
>> TeacherModePage1.java contains the following line:
>>  private TeacherMode teacherMode = new TeacherMode();
>>
>> I belived that when new page would be displayed (whe user clicks
>> TeacherMode
>> in TeacherBorder) a brand new TeacherMode instance would be returned but
>> is
>> not. And is not because all the classes are already instantiated and T5
>> gives them back to the user for efficiency.
>>
>> Please keep in mind this is just the beggining of the work, so not
>> everything is like it should be from architectural point of view (i.e.
>> @Persist will be replaced by onPassvate and onActivate). I just wanted to
>> see how it works.
>>
>> If any more details are reqiured let me know.
>>
>> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
>> --
>> View this message in context:
>> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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
>>
>>
> 
> 
> -- 
> Olle Hallin
> Senior Java Developer and Architect
> olle.hallin@crisp.se
> www.crisp.se
> 
> 

-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21010764.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: Layout Border component problem

Posted by kawes <ra...@gmail.com>.
Thanks a lot Jonathan, 

your pattern seems to be sensible and I'll follow your advice.

cheers


Jonathan Barker wrote:
> 
> 
> They are not quite interchangeable, but it can be fun figuring out which
> to
> use.  
> 
> In addition to onActivate and setupRender, you should also look at
> onPrepare
> for form submissions.  
> 
> I tend to just set id's in onActivate and leave heavier loading for
> onPrepare/setupRender.  Having said that, I think that the
> tapestry-hibernate integration does primary key encoding to allow the use
> of
> entities for onActivate/onPassivate.
> 
> Jonathan
> 
> 
> 
> 
>> -----Original Message-----
>> From: kawes [mailto:rafal.kawecki@gmail.com]
>> Sent: Monday, December 15, 2008 12:14
>> To: users@tapestry.apache.org
>> Subject: Re: Layout Border component problem
>> 
>> 
>> Hi Olle,
>> 
>> I finally got home and was able to check out your suggestion.
>> Works perfectly but I still have a small question:
>> 
>> I also used onActivate() to paste your code and it works as well.
>> So my question is: is it big difference between those methods and can
>> both
>> be used interchangeably or this was only coincidence
>> 
>> Thanks again, I can finally continue on my work.
>> 
>> cheers
>> 
>> 
>> Olle Hallin wrote:
>> >
>> > What happens is that TeacherMode is mutable, and hence leaks state
>> between
>> > different users. You are *not* given a fresh instance on each request.
>> > Instead, instances are pooled and reused.
>> >
>> > (Starting with 5.0.17,  it is forbidden to have initial values on page
>> > member variables in order to prevent bugs like this.)
>> >
>> > One way to handle this situation is:
>> >
>> > *@Persist
>> > *private TeacherMode teacherMode;
>> >
>> > public void *setupRender()* {
>> >   if (teacherMode == null) {
>> >     teacherMode = new TeacherMode(); // This will be a private instance
>> > per
>> > session
>> >   }
>> > }
>> >
>> > HTH,
>> >
>> > Olle
>> >
>> >
>> > 2008/12/15 kawes <ra...@gmail.com>
>> >
>> >>
>> >> Hi Jonathan,
>> >>
>> >> thanks for your quick response.
>> >> As you asked I uploaded classes I hit the problem in.
>> >>
>> >> Small description: One of my sub-application is Teacher (should be
>> able
>> >> to
>> >> provide a word in foreign language and accept user's answer checks
>> >> wheather
>> >> it is correct)
>> >>
>> >> When user logs in, clicks teacher link is redirected to AvailabaleSets
>> >> (which is wrapped by TeacherBorder).
>> >>
>> >> T5.zip file uploaded and it contains:
>> >>  - Border.java
>> >>  - Border.tml (pagelinks to all stuff provided by my app)
>> >>
>> >>  - TeacherBorder.java
>> >>  - TeacherBorder.tml (contains all links to navigate my Teacher
>> >> sub-application - i.e. TeacherMode - resposnible for 'asking
>> question',
>> >> registering results etc)
>> >>
>> >>  - AvailableSets.java
>> >>  - AvailableSets.tml (displays available sets containg words)
>> >>
>> >>  - TeacherModePage1.java
>> >>  - TeacherModePage1.tml (lets user to choose the word's set and decide
>> >> about
>> >> the questioning mode (mingled or the sequence of words had been added
>> to
>> >> the
>> >> set) )
>> >>
>> >>  - TeacherModePage2.java
>> >>  - TeacherModePage2.tml (displays questions and lets to type in
>> answers)
>> >>
>> >> TeacherModePage1.java contains the following line:
>> >>  private TeacherMode teacherMode = new TeacherMode();
>> >>
>> >> I belived that when new page would be displayed (whe user clicks
>> >> TeacherMode
>> >> in TeacherBorder) a brand new TeacherMode instance would be returned
>> but
>> >> is
>> >> not. And is not because all the classes are already instantiated and
>> T5
>> >> gives them back to the user for efficiency.
>> >>
>> >> Please keep in mind this is just the beggining of the work, so not
>> >> everything is like it should be from architectural point of view (i.e.
>> >> @Persist will be replaced by onPassvate and onActivate). I just wanted
>> to
>> >> see how it works.
>> >>
>> >> If any more details are reqiured let me know.
>> >>
>> >> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Layout-Border-component-problem-
>> tp21004400p21009484.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
>> >>
>> >>
>> >
>> >
>> > --
>> > Olle Hallin
>> > Senior Java Developer and Architect
>> > olle.hallin@crisp.se
>> > www.crisp.se
>> >
>> >
>> 
>> --
>> View this message in context: http://www.nabble.com/Layout-Border-
>> component-problem-tp21004400p21017812.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
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21020533.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: Layout Border component problem

Posted by Jonathan Barker <jo...@gmail.com>.
They are not quite interchangeable, but it can be fun figuring out which to
use.  

In addition to onActivate and setupRender, you should also look at onPrepare
for form submissions.  

I tend to just set id's in onActivate and leave heavier loading for
onPrepare/setupRender.  Having said that, I think that the
tapestry-hibernate integration does primary key encoding to allow the use of
entities for onActivate/onPassivate.

Jonathan




> -----Original Message-----
> From: kawes [mailto:rafal.kawecki@gmail.com]
> Sent: Monday, December 15, 2008 12:14
> To: users@tapestry.apache.org
> Subject: Re: Layout Border component problem
> 
> 
> Hi Olle,
> 
> I finally got home and was able to check out your suggestion.
> Works perfectly but I still have a small question:
> 
> I also used onActivate() to paste your code and it works as well.
> So my question is: is it big difference between those methods and can both
> be used interchangeably or this was only coincidence
> 
> Thanks again, I can finally continue on my work.
> 
> cheers
> 
> 
> Olle Hallin wrote:
> >
> > What happens is that TeacherMode is mutable, and hence leaks state
> between
> > different users. You are *not* given a fresh instance on each request.
> > Instead, instances are pooled and reused.
> >
> > (Starting with 5.0.17,  it is forbidden to have initial values on page
> > member variables in order to prevent bugs like this.)
> >
> > One way to handle this situation is:
> >
> > *@Persist
> > *private TeacherMode teacherMode;
> >
> > public void *setupRender()* {
> >   if (teacherMode == null) {
> >     teacherMode = new TeacherMode(); // This will be a private instance
> > per
> > session
> >   }
> > }
> >
> > HTH,
> >
> > Olle
> >
> >
> > 2008/12/15 kawes <ra...@gmail.com>
> >
> >>
> >> Hi Jonathan,
> >>
> >> thanks for your quick response.
> >> As you asked I uploaded classes I hit the problem in.
> >>
> >> Small description: One of my sub-application is Teacher (should be able
> >> to
> >> provide a word in foreign language and accept user's answer checks
> >> wheather
> >> it is correct)
> >>
> >> When user logs in, clicks teacher link is redirected to AvailabaleSets
> >> (which is wrapped by TeacherBorder).
> >>
> >> T5.zip file uploaded and it contains:
> >>  - Border.java
> >>  - Border.tml (pagelinks to all stuff provided by my app)
> >>
> >>  - TeacherBorder.java
> >>  - TeacherBorder.tml (contains all links to navigate my Teacher
> >> sub-application - i.e. TeacherMode - resposnible for 'asking question',
> >> registering results etc)
> >>
> >>  - AvailableSets.java
> >>  - AvailableSets.tml (displays available sets containg words)
> >>
> >>  - TeacherModePage1.java
> >>  - TeacherModePage1.tml (lets user to choose the word's set and decide
> >> about
> >> the questioning mode (mingled or the sequence of words had been added
> to
> >> the
> >> set) )
> >>
> >>  - TeacherModePage2.java
> >>  - TeacherModePage2.tml (displays questions and lets to type in
> answers)
> >>
> >> TeacherModePage1.java contains the following line:
> >>  private TeacherMode teacherMode = new TeacherMode();
> >>
> >> I belived that when new page would be displayed (whe user clicks
> >> TeacherMode
> >> in TeacherBorder) a brand new TeacherMode instance would be returned
> but
> >> is
> >> not. And is not because all the classes are already instantiated and T5
> >> gives them back to the user for efficiency.
> >>
> >> Please keep in mind this is just the beggining of the work, so not
> >> everything is like it should be from architectural point of view (i.e.
> >> @Persist will be replaced by onPassvate and onActivate). I just wanted
> to
> >> see how it works.
> >>
> >> If any more details are reqiured let me know.
> >>
> >> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Layout-Border-component-problem-
> tp21004400p21009484.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
> >>
> >>
> >
> >
> > --
> > Olle Hallin
> > Senior Java Developer and Architect
> > olle.hallin@crisp.se
> > www.crisp.se
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/Layout-Border-
> component-problem-tp21004400p21017812.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


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


Re: Layout Border component problem

Posted by kawes <ra...@gmail.com>.
Hi Olle, 

I finally got home and was able to check out your suggestion. 
Works perfectly but I still have a small question:

I also used onActivate() to paste your code and it works as well. 
So my question is: is it big difference between those methods and can both
be used interchangeably or this was only coincidence

Thanks again, I can finally continue on my work.

cheers


Olle Hallin wrote:
> 
> What happens is that TeacherMode is mutable, and hence leaks state between
> different users. You are *not* given a fresh instance on each request.
> Instead, instances are pooled and reused.
> 
> (Starting with 5.0.17,  it is forbidden to have initial values on page
> member variables in order to prevent bugs like this.)
> 
> One way to handle this situation is:
> 
> *@Persist
> *private TeacherMode teacherMode;
> 
> public void *setupRender()* {
>   if (teacherMode == null) {
>     teacherMode = new TeacherMode(); // This will be a private instance
> per
> session
>   }
> }
> 
> HTH,
> 
> Olle
> 
> 
> 2008/12/15 kawes <ra...@gmail.com>
> 
>>
>> Hi Jonathan,
>>
>> thanks for your quick response.
>> As you asked I uploaded classes I hit the problem in.
>>
>> Small description: One of my sub-application is Teacher (should be able
>> to
>> provide a word in foreign language and accept user's answer checks
>> wheather
>> it is correct)
>>
>> When user logs in, clicks teacher link is redirected to AvailabaleSets
>> (which is wrapped by TeacherBorder).
>>
>> T5.zip file uploaded and it contains:
>>  - Border.java
>>  - Border.tml (pagelinks to all stuff provided by my app)
>>
>>  - TeacherBorder.java
>>  - TeacherBorder.tml (contains all links to navigate my Teacher
>> sub-application - i.e. TeacherMode - resposnible for 'asking question',
>> registering results etc)
>>
>>  - AvailableSets.java
>>  - AvailableSets.tml (displays available sets containg words)
>>
>>  - TeacherModePage1.java
>>  - TeacherModePage1.tml (lets user to choose the word's set and decide
>> about
>> the questioning mode (mingled or the sequence of words had been added to
>> the
>> set) )
>>
>>  - TeacherModePage2.java
>>  - TeacherModePage2.tml (displays questions and lets to type in answers)
>>
>> TeacherModePage1.java contains the following line:
>>  private TeacherMode teacherMode = new TeacherMode();
>>
>> I belived that when new page would be displayed (whe user clicks
>> TeacherMode
>> in TeacherBorder) a brand new TeacherMode instance would be returned but
>> is
>> not. And is not because all the classes are already instantiated and T5
>> gives them back to the user for efficiency.
>>
>> Please keep in mind this is just the beggining of the work, so not
>> everything is like it should be from architectural point of view (i.e.
>> @Persist will be replaced by onPassvate and onActivate). I just wanted to
>> see how it works.
>>
>> If any more details are reqiured let me know.
>>
>> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
>> --
>> View this message in context:
>> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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
>>
>>
> 
> 
> -- 
> Olle Hallin
> Senior Java Developer and Architect
> olle.hallin@crisp.se
> www.crisp.se
> 
> 

-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21017812.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: Layout Border component problem

Posted by Olle Hallin <ol...@gmail.com>.
What happens is that TeacherMode is mutable, and hence leaks state between
different users. You are *not* given a fresh instance on each request.
Instead, instances are pooled and reused.

(Starting with 5.0.17,  it is forbidden to have initial values on page
member variables in order to prevent bugs like this.)

One way to handle this situation is:

*@Persist
*private TeacherMode teacherMode;

public void *setupRender()* {
  if (teacherMode == null) {
    teacherMode = new TeacherMode(); // This will be a private instance per
session
  }
}

HTH,

Olle


2008/12/15 kawes <ra...@gmail.com>

>
> Hi Jonathan,
>
> thanks for your quick response.
> As you asked I uploaded classes I hit the problem in.
>
> Small description: One of my sub-application is Teacher (should be able to
> provide a word in foreign language and accept user's answer checks wheather
> it is correct)
>
> When user logs in, clicks teacher link is redirected to AvailabaleSets
> (which is wrapped by TeacherBorder).
>
> T5.zip file uploaded and it contains:
>  - Border.java
>  - Border.tml (pagelinks to all stuff provided by my app)
>
>  - TeacherBorder.java
>  - TeacherBorder.tml (contains all links to navigate my Teacher
> sub-application - i.e. TeacherMode - resposnible for 'asking question',
> registering results etc)
>
>  - AvailableSets.java
>  - AvailableSets.tml (displays available sets containg words)
>
>  - TeacherModePage1.java
>  - TeacherModePage1.tml (lets user to choose the word's set and decide
> about
> the questioning mode (mingled or the sequence of words had been added to
> the
> set) )
>
>  - TeacherModePage2.java
>  - TeacherModePage2.tml (displays questions and lets to type in answers)
>
> TeacherModePage1.java contains the following line:
>  private TeacherMode teacherMode = new TeacherMode();
>
> I belived that when new page would be displayed (whe user clicks
> TeacherMode
> in TeacherBorder) a brand new TeacherMode instance would be returned but is
> not. And is not because all the classes are already instantiated and T5
> gives them back to the user for efficiency.
>
> Please keep in mind this is just the beggining of the work, so not
> everything is like it should be from architectural point of view (i.e.
> @Persist will be replaced by onPassvate and onActivate). I just wanted to
> see how it works.
>
> If any more details are reqiured let me know.
>
> Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip
> --
> View this message in context:
> http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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
>
>


-- 
Olle Hallin
Senior Java Developer and Architect
olle.hallin@crisp.se
www.crisp.se

RE: Layout Border component problem

Posted by kawes <ra...@gmail.com>.
Hi Jonathan, 

thanks for your quick response.
As you asked I uploaded classes I hit the problem in.

Small description: One of my sub-application is Teacher (should be able to
provide a word in foreign language and accept user's answer checks wheather
it is correct)

When user logs in, clicks teacher link is redirected to AvailabaleSets
(which is wrapped by TeacherBorder).

T5.zip file uploaded and it contains:
 - Border.java
 - Border.tml (pagelinks to all stuff provided by my app)

 - TeacherBorder.java
 - TeacherBorder.tml (contains all links to navigate my Teacher
sub-application - i.e. TeacherMode - resposnible for 'asking question',
registering results etc) 

 - AvailableSets.java
 - AvailableSets.tml (displays available sets containg words)

 - TeacherModePage1.java
 - TeacherModePage1.tml (lets user to choose the word's set and decide about
the questioning mode (mingled or the sequence of words had been added to the
set) )

 - TeacherModePage2.java
 - TeacherModePage2.tml (displays questions and lets to type in answers)

TeacherModePage1.java contains the following line:
 private TeacherMode teacherMode = new TeacherMode();

I belived that when new page would be displayed (whe user clicks TeacherMode
in TeacherBorder) a brand new TeacherMode instance would be returned but is
not. And is not because all the classes are already instantiated and T5
gives them back to the user for efficiency.

Please keep in mind this is just the beggining of the work, so not
everything is like it should be from architectural point of view (i.e.
@Persist will be replaced by onPassvate and onActivate). I just wanted to
see how it works.

If any more details are reqiured let me know.

Thanks in advance http://www.nabble.com/file/p21009484/T5.zip T5.zip 
-- 
View this message in context: http://www.nabble.com/Layout-Border-component-problem-tp21004400p21009484.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: Layout Border component problem

Posted by Jonathan Barker <jo...@gmail.com>.
Tapestry pools pages and components, so it is supposed to re-use an
available component rather than create a new one, if there is one available.
It's a little like a server having a pool of worker threads to service
requests.

If you are having problem with the state being shared between users, then
you have made a mistake in how you are using instance variables or
persisting state.  If you post your code, I'm sure your mistake can be
easily identified.

Jonathan


> -----Original Message-----
> From: kawes [mailto:rafal.kawecki@gmail.com]
> Sent: Sunday, December 14, 2008 15:43
> To: users@tapestry.apache.org
> Subject: Layout Border component problem
> 
> 
> Hi Guys,
> I just started to use T5 and lately I have hit a problem which I cannot
> resovle.
> 
> I created a Border component which contains a navigation menu.
> 
> I also created some kind of a sub-applications, let's call them MyMode1,
> MyMode2, MyMode3 etc and palced pagelinks to them in Border navigation.
> Then I implemented another border-like components MyMode1Border,
> MyMode2Border, MyMode3Border which are wrapped by Border and contains
> navigation specific to each Mode.
> 
> Now, when a new user logs in the Border page, containing pagelinks to each
> Mode, is being displayed.
> 
> Then the user chooses some Mode and starts doing some stuff.
> The problem is that when another user logs in and goes to the same Mode as
> the prevoius one
> he is given the same instance of the Mode so when he does some stuff on
> the
> page too he overrides what the other guy did.
> 
> I added System.out.println to the non-argument constructors of  each page
> and here is what I found out:
> 
> When I restart the server and the first user comes in, clicks login button
> the following instantiations take place:
> 
> com.kawecki.wapp.components.Border@617584
> [INFO] AppModule.TimingFilter Request time: 625 ms
> com.kawecki.wapp.components.MyMode1Border@2d09e0
> com.kawecki.wapp.components.Border@12297d7
> com.kawecki.wapp.components.MyMode2Border@11d20d3
> com.kawecki.wapp.components.Border@1562c67
> com.kawecki.wapp.components.MyMode3Border
> com.kawecki.wapp.components.Border@149249e
> [INFO] AppModule.TimingFilter Request time: 594 ms
> 
> Then, when the user clicks on one of the Mode pagelinks new objects are
> created just like above.
> But when new user logs in no new object are created and both of them uses
> the same instance of a MyMode1Border class.
> 
> I read about page pooling, onPassivate, onActivate but my problem seems to
> work just opposite.
> So if anybody could let me know what I do wrong I would appreciate a lot.
> 
> Hope I was clear enough
> Thanks in advance
> --
> View this message in context: http://www.nabble.com/Layout-Border-
> component-problem-tp21004400p21004400.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


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