In your case, you dont need the InjectPage.
try this:
public String getPageLinkContext() {
return "another";
}
with regards
Sven Homburg
Founder of the Chenille Kit Project
http://chenillekit.codehaus.org
2010/5/19 Albert Tumanov <[email protected]>
> Dear Tapestry users,
>
> I do not understand what @InjectPage actually does, can somebody please
> help me.
> I've expected that @InjectPage should return a fresh page from the
> pool, so that I can use it e.g. for creating page links with needed
> parameters.
> But if I try to inject a page in the same page class, it actually
> injects "this" instead of a fresh page instance.
>
> Example:
> Say we have a Product page showing some product details.
> It also shows links to related products (link to the same page but
> with different parameter).
>
> public class Product {
>
> private String name;
>
> void onActivate(String param) {
> this.name = param;
> }
>
> Object[] onPassivate() {
> return new Object[] { name };
> }
>
> @InjectPage
> private Product productPage;
>
> // in real life this method could be in a separate component
> public Object[] getPageLinkContext() {
> System.out.println("this=" + this);
> System.out.println("productPage=" + productPage);
> productPage.setName("another");
> return productPage.onPassivate();
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public String getName() {
> return name;
> }
> }
>
> Product.tml:
> <html t:type="layout" title="MyPage"
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
> xmlns:p="tapestry:parameter">
> This product = ${name}
> <t:pagelink page="Product" context="pageLinkContext">related
> product</t:pagelink>
> This product = ${name}
> </html>
>
> What I expect is that value of "name" should not change after PageLink
> component have called the getPageLinkContext() method.
> But actual generated HTML is (for
> http://localhost:8080/myapp/product/initial):
>
> This product = initial
> <a href="/myapp/product/another">related product</a>
> This product = another
>
> System output shows that the "productPage" is the same instance as "this":
>
> this=com.example.pages.prod...@90e1b2
> productpage=com.example.pages.prod...@90e1b2
>
> Is it the correct @InjectPage behaviour ?
> Am I doing something lame ?
>
> Thanks in advance,
> Albert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>