You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nima Boustanian <ni...@tn20.com> on 2006/03/28 15:49:23 UTC

Setting a component property in another page

Hey all

Okay, I thought this was easy but I've been trying to set a component 
property for a couple of hours now without getting anywhere.

First off, I have my page class along with a listener method:
..
public abstract Long getPostId();
public abstract void setPostId(Long postId);

@InjectPage("Item")
public abstract IPage getItemPage();

public IPage selectAction(Long postId) {
       //No code here yet. Just an empty listener.
}

public void setNextPageProperties(IRequestCycle cycle) {
        ConversationInfoJwc conversationInfoJwc =
              (ConversationInfoJwc) cycle.getPage("ConversationInfo"); 
//The component where I want to set the property in
        conversationInfoJwc.setPostId(getPostId());
        cycle.activate(getItemPage()); //The page which contains the 
component
    }
...

Which is called by:
...
<span jwcid="@DirectLink" listener="listener:selectAction" 
parameters="ognl:components.table.tableRow.id"> <span jwcid="@Insert" 
value="ognl:components.table.tableRow.title"/> </span>
...

I want to set the property of ConversationInfoJwc which is contained in 
the Item page somehow, but don't know how one should go about to
do it. I don't even know if the IRequestCycle is the proper interface to 
use when trying to set component parameters, are there other ways of 
doing this?


Thanks!

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


RE: Setting a component property in another page

Posted by James Carman <ja...@carmanconsulting.com>.
Have you tried using a ComponentAddress object to find the component?

-----Original Message-----
From: Mike Snare [mailto:mikesnare@gmail.com] 
Sent: Tuesday, March 28, 2006 8:57 AM
To: Tapestry users
Subject: Re: Setting a component property in another page

Are you trying to set a property of component that is contained within
a page?  How do you have any idea that the instance of
ConversationInfoJwc you are getting is the one used by the ItemPage
you are getting?  I think you have to assume that it isn't.

I think you need an ID setter on the ItemPage.  This could be used by
the page as a parameter to the ConversationInfoJwc component used by
the page.

-Mike

On 3/28/06, Nima Boustanian <ni...@tn20.com> wrote:
> Hey all
>
> Okay, I thought this was easy but I've been trying to set a component
> property for a couple of hours now without getting anywhere.
>
> First off, I have my page class along with a listener method:
> ..
> public abstract Long getPostId();
> public abstract void setPostId(Long postId);
>
> @InjectPage("Item")
> public abstract IPage getItemPage();
>
> public IPage selectAction(Long postId) {
>       //No code here yet. Just an empty listener.
> }
>
> public void setNextPageProperties(IRequestCycle cycle) {
>        ConversationInfoJwc conversationInfoJwc =
>              (ConversationInfoJwc) cycle.getPage("ConversationInfo");
> //The component where I want to set the property in
>        conversationInfoJwc.setPostId(getPostId());
>        cycle.activate(getItemPage()); //The page which contains the
> component
>    }
> ...
>
> Which is called by:
> ...
> <span jwcid="@DirectLink" listener="listener:selectAction"
> parameters="ognl:components.table.tableRow.id"> <span jwcid="@Insert"
> value="ognl:components.table.tableRow.title"/> </span>
> ...
>
> I want to set the property of ConversationInfoJwc which is contained in
> the Item page somehow, but don't know how one should go about to
> do it. I don't even know if the IRequestCycle is the proper interface to
> use when trying to set component parameters, are there other ways of
> doing this?
>
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

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




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


Re: Setting a component property in another page

Posted by Mike Snare <mi...@gmail.com>.
Are you trying to set a property of component that is contained within
a page?  How do you have any idea that the instance of
ConversationInfoJwc you are getting is the one used by the ItemPage
you are getting?  I think you have to assume that it isn't.

I think you need an ID setter on the ItemPage.  This could be used by
the page as a parameter to the ConversationInfoJwc component used by
the page.

-Mike

On 3/28/06, Nima Boustanian <ni...@tn20.com> wrote:
> Hey all
>
> Okay, I thought this was easy but I've been trying to set a component
> property for a couple of hours now without getting anywhere.
>
> First off, I have my page class along with a listener method:
> ..
> public abstract Long getPostId();
> public abstract void setPostId(Long postId);
>
> @InjectPage("Item")
> public abstract IPage getItemPage();
>
> public IPage selectAction(Long postId) {
>       //No code here yet. Just an empty listener.
> }
>
> public void setNextPageProperties(IRequestCycle cycle) {
>        ConversationInfoJwc conversationInfoJwc =
>              (ConversationInfoJwc) cycle.getPage("ConversationInfo");
> //The component where I want to set the property in
>        conversationInfoJwc.setPostId(getPostId());
>        cycle.activate(getItemPage()); //The page which contains the
> component
>    }
> ...
>
> Which is called by:
> ...
> <span jwcid="@DirectLink" listener="listener:selectAction"
> parameters="ognl:components.table.tableRow.id"> <span jwcid="@Insert"
> value="ognl:components.table.tableRow.title"/> </span>
> ...
>
> I want to set the property of ConversationInfoJwc which is contained in
> the Item page somehow, but don't know how one should go about to
> do it. I don't even know if the IRequestCycle is the proper interface to
> use when trying to set component parameters, are there other ways of
> doing this?
>
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

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


Re: Setting a component property in another page

Posted by Nima Boustanian <ni...@tn20.com>.
Works like a freakin' charm. Thanks!

Mike Snare wrote:

>Inject the item page via an annotation.
>
>get it, set the property, and return it all in your select action:
>
>// returns the page to go to
>public ItemPage selectAction(Long postId) {
>  //Grabs the postId from a directLink parameter
>  //setPostId(postId); don't think you need this...
>  ItemPage ip = getItemPage();
>  ip.setPostId(postId);
>  return ip;
>}
>
>Will that work for you?
>
>On 3/28/06, Nima Boustanian <ni...@tn20.com> wrote:
>  
>
>>Okay guys, I took your advice and made the appropriate changes (am using
>>the InjectComponent annotation, made a page property
>>that maps to the component property and so forth.)
>>
>>The only thing that's left is that I can't figure out how to call the
>>goItemPage method in the first page class:
>>
>>public abstract Long getPostId();
>>public abstract void setPostId(Long postId);
>>
>>public void selectAction(Long postId) {     //Grabs the postId from a
>>directLink parameter
>>       setPostId(postId);
>>       //Now that we have the postId, how can we call the next method
>>which sets the property and takes us to the next page?
>>}
>>
>>public void goItemPage(IRequestCycle cycle) {
>>       Item itemPage =
>>           (Item) cycle.getPage("Item");
>>       ....
>>   }
>>
>>Any further suggestions or do's or don't's?
>>
>>Thanks!
>>
>>Mike Snare wrote:
>>
>>    
>>
>>>Doesn't it make more sense to set the value on the page and have the
>>>page deal with it however it needs to -- in this case by setting the
>>>id on the component in the page.
>>>
>>>It seems that the components used by a particular page are
>>>implementation details for that page that should not be exposed when
>>>there is another solution.  The user of the page doesn't need to know
>>>about the Conversation component, only that the page needs an id to do
>>>it's job.  Law of demeter and all that...
>>>
>>>-Mike
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>  
>


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


Re: Setting a component property in another page

Posted by Mike Snare <mi...@gmail.com>.
Inject the item page via an annotation.

get it, set the property, and return it all in your select action:

// returns the page to go to
public ItemPage selectAction(Long postId) {
  //Grabs the postId from a directLink parameter
  //setPostId(postId); don't think you need this...
  ItemPage ip = getItemPage();
  ip.setPostId(postId);
  return ip;
}

Will that work for you?

On 3/28/06, Nima Boustanian <ni...@tn20.com> wrote:
> Okay guys, I took your advice and made the appropriate changes (am using
> the InjectComponent annotation, made a page property
> that maps to the component property and so forth.)
>
> The only thing that's left is that I can't figure out how to call the
> goItemPage method in the first page class:
>
> public abstract Long getPostId();
> public abstract void setPostId(Long postId);
>
> public void selectAction(Long postId) {     //Grabs the postId from a
> directLink parameter
>        setPostId(postId);
>        //Now that we have the postId, how can we call the next method
> which sets the property and takes us to the next page?
> }
>
> public void goItemPage(IRequestCycle cycle) {
>        Item itemPage =
>            (Item) cycle.getPage("Item");
>        ....
>    }
>
> Any further suggestions or do's or don't's?
>
> Thanks!
>
> Mike Snare wrote:
>
> >Doesn't it make more sense to set the value on the page and have the
> >page deal with it however it needs to -- in this case by setting the
> >id on the component in the page.
> >
> >It seems that the components used by a particular page are
> >implementation details for that page that should not be exposed when
> >there is another solution.  The user of the page doesn't need to know
> >about the Conversation component, only that the page needs an id to do
> >it's job.  Law of demeter and all that...
> >
> >-Mike
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

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


Re: Setting a component property in another page

Posted by Nima Boustanian <ni...@tn20.com>.
Okay guys, I took your advice and made the appropriate changes (am using 
the InjectComponent annotation, made a page property
that maps to the component property and so forth.)

The only thing that's left is that I can't figure out how to call the 
goItemPage method in the first page class:

public abstract Long getPostId();
public abstract void setPostId(Long postId);

public void selectAction(Long postId) {     //Grabs the postId from a 
directLink parameter
        setPostId(postId);
        //Now that we have the postId, how can we call the next method 
which sets the property and takes us to the next page?
}

public void goItemPage(IRequestCycle cycle) {
        Item itemPage =
            (Item) cycle.getPage("Item");
        ....
    }

Any further suggestions or do's or don't's?

Thanks!

Mike Snare wrote:

>Doesn't it make more sense to set the value on the page and have the
>page deal with it however it needs to -- in this case by setting the
>id on the component in the page.
>
>It seems that the components used by a particular page are
>implementation details for that page that should not be exposed when
>there is another solution.  The user of the page doesn't need to know
>about the Conversation component, only that the page needs an id to do
>it's job.  Law of demeter and all that...
>
>-Mike
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>  
>


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


Re: Setting a component property in another page

Posted by Mike Snare <mi...@gmail.com>.
Doesn't it make more sense to set the value on the page and have the
page deal with it however it needs to -- in this case by setting the
id on the component in the page.

It seems that the components used by a particular page are
implementation details for that page that should not be exposed when
there is another solution.  The user of the page doesn't need to know
about the Conversation component, only that the page needs an id to do
it's job.  Law of demeter and all that...

-Mike

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


Re: Setting a component property in another page

Posted by Adam Zimowski <zi...@gmail.com>.
Nima,

I'd be curious to see the code for your "next" page. I'm guessing you
don't have:

@InjectComponent("nameofyourcomponent")
public abstract ConversationInfoJwc getConversationInfoJwc();

Then, from the previous page (the one you showed us), just call the
abstract getter to get ahold of component reference and things should
work.

I also have  a few suggestions.  Since it looks like you're on JDK
1.5, take advantage of auto-boxing feature. It makes life a whole lot
easier. Another words, you don't need to worry about passing wrappers
for simple types like: Long, Integer, etc.. Just use raw data type and
1.5 will auto-magically box it for you.

Also, we recently discussed (in another thread) the fact that
excessive dots in OGNL calls eventually make for lower performance.
Try to wrap your call with a page-level Java method, and return
directly an object you want. Then, just call that method instead. It
will be a whole lot faster.

> value="ognl:components.table.tableRow.title"/>

Do something like:

public String getTitle() {
 return getComponents(). etc... getTItle();
}

Then:

value="ognl:title"

Regards,

Adam
On 3/28/06, Nima Boustanian <ni...@tn20.com> wrote:
> Hey all
>
> Okay, I thought this was easy but I've been trying to set a component
> property for a couple of hours now without getting anywhere.
>
> First off, I have my page class along with a listener method:
> ..
> public abstract Long getPostId();
> public abstract void setPostId(Long postId);
>
> @InjectPage("Item")
> public abstract IPage getItemPage();
>
> public IPage selectAction(Long postId) {
>        //No code here yet. Just an empty listener.
> }
>
> public void setNextPageProperties(IRequestCycle cycle) {
>         ConversationInfoJwc conversationInfoJwc =
>               (ConversationInfoJwc) cycle.getPage("ConversationInfo");
> //The component where I want to set the property in
>         conversationInfoJwc.setPostId(getPostId());
>         cycle.activate(getItemPage()); //The page which contains the
> component
>     }
> ...
>
> Which is called by:
> ...
> <span jwcid="@DirectLink" listener="listener:selectAction"
> parameters="ognl:components.table.tableRow.id"> <span jwcid="@Insert"
> value="ognl:components.table.tableRow.title"/> </span>
> ...
>
> I want to set the property of ConversationInfoJwc which is contained in
> the Item page somehow, but don't know how one should go about to
> do it. I don't even know if the IRequestCycle is the proper interface to
> use when trying to set component parameters, are there other ways of
> doing this?
>
>
> Thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

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