See, it's two different instances of the same component. What you are
looking for is something almost akin to a static field.

The "request scope" variable is tempting in this specific use case, but
troubling in most others. It brings with it all the ugliness of naming
coincidences and such from the JSP world.

The Tapestry equivalent of this would be an ASO (application state object)
that was stored in the request, transiently. Then different components (or
different instances of the same component) could inject the ASO.  This is
not built into Tapestry, but defining an ASO scope of request is just a few
lines of work (the trick is the RIGHT lines, of course).

If you look at the code:

http://svn.apache.org/repos/asf/tapestry/tapestry4/tags/4.0.2/framework/src/java/org/apache/tapestry/engine/state/SessionScopeManager.java

You can see how you could easily build a version that read and updated keys
in the WebRequest rather than the WebSession.


On 11/2/06, Gurps <[EMAIL PROTECTED]> wrote:


Karthik, i'll try the methods below too.
I guess what i'm trying to understand is the equivalent of a JSP
RequestScope. To me, the component should just "remember" it's value
between
pages (and not session scope), but i'm still unclear.

Also in my app below, i don't think the component is really being "shared"
but rather duplicated twice even though it's a component - am I correct in
my own example? I think it may be better to put teh component in a Border
type component itself. I was looking at the Tapestry Petstore example
(implemented in Tap 3 at http://pwp.netcabo.pt/lneves/tapestryapps/). They
have a search component in a border but i don't know if it "persists" it's
search words between page requests. Can anyone find a running demo online
somewhere?

Confused :-/


karthik.nar wrote:
>
> glad it worked.
>
> i think one of the powers of tapestry is the ability to be able to tap
> into
> lifecycle methods, as also register listeners (like pageBeginRender)
>
> i don't have exact answers to your question "but is this optimal?" - it
> depends on what you want to do.  if you want your component to be
agnostic
> of the page it is in, then it's better to follow the approach of the
page
> injecting the initial value as done below.
>
> you could also configure your component to accept a parameter and set
that
> as the initial value of the text field.  this parameter could then be
> bound
> to a value on your page.
>
> hth - karthik.
>
>
> On 11/2/06, Gurps <[EMAIL PROTECTED]> wrote:
>>
>>
>> Karthik.Nar,
>>
>> I made the change below to Result.java. It seems to work, but is this
>> optimal? Is there a way for the component to automatically find out
it's
>> "parent page" to bind the value without using a "double" bucket brigade
>> and/or without using component injection. I'm new to Tapestry still, so
>> might not understand even what i'm talking about!
>> Is this the best practice? Thank you for your advice.
>>
>> Result.java
>> -------------------
>> package uk.co.gd.dao;
>>
>> import org.apache.tapestry.annotations.InjectComponent;
>> import org.apache.tapestry.event.PageBeginRenderListener;
>> import org.apache.tapestry.event.PageEvent;
>> import org.apache.tapestry.html.BasePage;
>>
>> public abstract class Result extends BasePage implements
>> PageBeginRenderListener {
>>
>>         @InjectComponent("searchComponent")
>>         public abstract SearchComponent getSearchComponent();
>>
>>         public abstract void setSearchText(String searchText);
>>         public abstract String getSearchText();
>>
>>         public void pageBeginRender(PageEvent event) {
>>                 if (event.getRequestCycle().isRewinding()) {
>>                         System.out.println("in pagebeginrender but
>> rewinding");
>>                         return;
>>                 }
>>
>>                 System.out.println("in pagebeginrender not rewinding");
>>
>>                 ((SearchComponent)
>> getSearchComponent()).setSearchText(getSearchText());
>>         }
>> }
>>
>>
>>
>>
>
>

--
View this message in context:
http://www.nabble.com/Component-won%27t-remember-value-tf2547494.html#a7142978
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

Reply via email to