Re: Component won't remember value
I did some more experimenting and ended up using a Border component. However, how do I set the value of something that is in a border? I tried treating it like any other component eg: ((Border) getBorder()).setSearchText(getSearchText()) but it didn't work. I think the Border component is treated a little differently to vanilla components? 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#a7197552 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Component won't remember value
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
Re: Component won't remember value
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]
Re: Component won't remember value
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()); } }
Re: Component won't remember value
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()); } } karthik.nar wrote: > > you are setting the searchText on the Result page and not on the > SearchComponent in the result page. > > since you have the searchText on the Result page you need to now > "transfer" > it to the SearchComponent in the result page. > > you can consider setting the searchText of the SearchComponent in the > pageBeginRender method of Result.java > > On 10/31/06, Gurps <[EMAIL PROTECTED]> wrote: >> >> >> I have 2 pages. A Home.html and a Result.html. >> I have 1 component (SearchComponent) which is to be SHARED across both >> pages. The component is a simple textfield. >> >> When submitting a value in the first page, it then goes to the result >> page. >> However the component don't remember it's value the first time. On >> subsequent submits it remembers it (probably because you stay on the >> reult >> page behind the scenes). >> >> Does anyone have any idea what to do? Much appreciated. Here is the >> simple >> code: >> >> Home.java >> --- >> package uk.co.gd.dao; >> >> import org.apache.tapestry.html.BasePage; >> >> public abstract class Home extends BasePage { >> } >> >> >> Home.page >> --- >> >> > Foundation//Tapestry >> Specification 4.0//EN" >> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> >> >> >> >> >> >> >> Home.html >> >> >> >> >> >> >> >> >> Result.java >> >> package uk.co.gd.dao; >> >> import org.apache.tapestry.html.BasePage; >> >> public abstract class Result extends BasePage { >> public abstract void setSearchText(String searchText); >> } >> >> >> >> Result.page >> -- >> >> > Foundation//Tapestry >> Specification 4.0//EN" >> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> >> >> >> >> >> >> >> Result.html >> >> >> >> you entered: >> >> >> >> >> SearchComponent.java >> - >> package uk.co.gd.dao; >> >> import org.apache.tapestry.BaseComponent; >> import org.apache.tapestry.IPage; >> import org.apache.tapestry.IRequestCycle; >> import org.apache.tapestry.annotations.InitialValue; >> import org.apache.tapestry.annotations.InjectPage; >> >> public abstract class SearchComponent extends BaseComponent { >> >> @InjectPage("Result") >> public abstract Result getResultPage(); >> >> @InitialValue("literal:") >> public abstract String getSearchText(); >> >> public IPage onOk(IRequestCycle cycle) { >> System.out.println(new java.util.Date() + ": over here >> SearchComponent: " >> + getSearchText()); >> >> if (cycle.isRewinding()) >> System.out.println(new java.util.Date() + ": over >> here SearchComponent: >> rewinding"); >> else >> System.out.println(new java.util.Date() + ": over >> here SearchComponent: >> not rewinding"); >> >> Result resultPage = getResultPage(); >> resultPage.setSearchText(getSearchText()); >> return resultPage; >> } >> } >> >> >> SearchComponent.jwc >> >> >> > Foundation//Tapestry Specification 4.0//EN" >> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> SearchComponent.html >> >> >> >> >>
Re: Component won't remember value
you are setting the searchText on the Result page and not on the SearchComponent in the result page. since you have the searchText on the Result page you need to now "transfer" it to the SearchComponent in the result page. you can consider setting the searchText of the SearchComponent in the pageBeginRender method of Result.java On 10/31/06, Gurps <[EMAIL PROTECTED]> wrote: I have 2 pages. A Home.html and a Result.html. I have 1 component (SearchComponent) which is to be SHARED across both pages. The component is a simple textfield. When submitting a value in the first page, it then goes to the result page. However the component don't remember it's value the first time. On subsequent submits it remembers it (probably because you stay on the reult page behind the scenes). Does anyone have any idea what to do? Much appreciated. Here is the simple code: Home.java --- package uk.co.gd.dao; import org.apache.tapestry.html.BasePage; public abstract class Home extends BasePage { } Home.page --- http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> Home.html Result.java package uk.co.gd.dao; import org.apache.tapestry.html.BasePage; public abstract class Result extends BasePage { public abstract void setSearchText(String searchText); } Result.page -- http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> Result.html you entered: SearchComponent.java - package uk.co.gd.dao; import org.apache.tapestry.BaseComponent; import org.apache.tapestry.IPage; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.annotations.InitialValue; import org.apache.tapestry.annotations.InjectPage; public abstract class SearchComponent extends BaseComponent { @InjectPage("Result") public abstract Result getResultPage(); @InitialValue("literal:") public abstract String getSearchText(); public IPage onOk(IRequestCycle cycle) { System.out.println(new java.util.Date() + ": over here SearchComponent: " + getSearchText()); if (cycle.isRewinding()) System.out.println(new java.util.Date() + ": over here SearchComponent: rewinding"); else System.out.println(new java.util.Date() + ": over here SearchComponent: not rewinding"); Result resultPage = getResultPage(); resultPage.setSearchText(getSearchText()); return resultPage; } } SearchComponent.jwc http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> SearchComponent.html -- View this message in context: http://www.nabble.com/Component-won%27t-remember-value-tf2547494.html#a7099616 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Thanks, Karthik
Component won't remember value
I have 2 pages. A Home.html and a Result.html. I have 1 component (SearchComponent) which is to be SHARED across both pages. The component is a simple textfield. When submitting a value in the first page, it then goes to the result page. However the component don't remember it's value the first time. On subsequent submits it remembers it (probably because you stay on the reult page behind the scenes). Does anyone have any idea what to do? Much appreciated. Here is the simple code: Home.java --- package uk.co.gd.dao; import org.apache.tapestry.html.BasePage; public abstract class Home extends BasePage { } Home.page --- http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> Home.html Result.java package uk.co.gd.dao; import org.apache.tapestry.html.BasePage; public abstract class Result extends BasePage { public abstract void setSearchText(String searchText); } Result.page -- http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> Result.html you entered: SearchComponent.java - package uk.co.gd.dao; import org.apache.tapestry.BaseComponent; import org.apache.tapestry.IPage; import org.apache.tapestry.IRequestCycle; import org.apache.tapestry.annotations.InitialValue; import org.apache.tapestry.annotations.InjectPage; public abstract class SearchComponent extends BaseComponent { @InjectPage("Result") public abstract Result getResultPage(); @InitialValue("literal:") public abstract String getSearchText(); public IPage onOk(IRequestCycle cycle) { System.out.println(new java.util.Date() + ": over here SearchComponent: " + getSearchText()); if (cycle.isRewinding()) System.out.println(new java.util.Date() + ": over here SearchComponent: rewinding"); else System.out.println(new java.util.Date() + ": over here SearchComponent: not rewinding"); Result resultPage = getResultPage(); resultPage.setSearchText(getSearchText()); return resultPage; } } SearchComponent.jwc http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";> SearchComponent.html -- View this message in context: http://www.nabble.com/Component-won%27t-remember-value-tf2547494.html#a7099616 Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]