You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Leo Sakhvoruk <le...@gmail.com> on 2005/03/25 20:58:45 UTC

Dynamically setting page properties and invoking pages.

Hi,

I'm fairly new to Tapestry but I have read Howard's book and have been 
working on a project using it (Tapestry) for a few weeks. The issue I'm 
running up against is as follows.

I'm creating a page which includes a menu generating component. This 
component requires an array of strings corresponding to page names and 
then renders the menu using DirecLinks, each link containing 2 
parameters: 1) the name of the page, 2) a record. The component has a 
listener that gets invoked when the link is clicked. Now my problem is 
that each page renders information contained within the record and so 
has to have the record. I was wondering if there is some way, when the 
menu component listener is invoked, to set the record for the page to be 
activated without having to explicitly instantiate the page class?

I was trying something to the effect of:

public class MenuComponent extends BaseComponent{
    public void loadPage(IRequestCycle cycle){
      String page = (String)cycle.getServiceParameters()[0];
      RecordClass record = (RecordClass)cycle.getServiceParameters()[1];

       cycle.getPage(page).setProperty("record", record);
       cycle.activate(page);
    }
}

Then the target page would have this in it's .page file:

<property-specification name="record" type="package.RecordClass" 
persistent="no"/>

with associated getter and setter methods in the class file.

However, when the target page renders the record is null. I'm guessing 
here that the setProperty() method is used to set something other than 
the <property-specification> of the page, but I wasn't sure.

My reason for doing all of this is so that I can dynamically add links 
to the menu.

Thanks in advance for any direction,

Leo

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


Re: Dynamically setting page properties and invoking pages.

Posted by Theo vN <th...@gmail.com>.
On Fri, 25 Mar 2005 13:58:45 -0600, Leo Sakhvoruk
<le...@gmail.com> wrote:
> public class MenuComponent extends BaseComponent{
>     public void loadPage(IRequestCycle cycle){
>       String page = (String)cycle.getServiceParameters()[0];
>       RecordClass record = (RecordClass)cycle.getServiceParameters()[1];
> 
>        cycle.getPage(page).setProperty("record", record);
>        cycle.activate(page);
>     }
> }
I stand to be corrected but I have a feeling that you are possibly
setting the property of an instance one page and then activating
another. Try something like this..

IPage gotopage = cycle.getPage(page);
gotopage.setProperty...
cycle.activate(gotopage);

-- 
Cheers
Theo

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


Re: Dynamically setting page properties and invoking pages.

Posted by Leo Sakhvoruk <le...@gmail.com>.
Ok issue solved!

What I did was move the method that accessed the record on the target 
page from finishLoad() to pageBeginRender() (implemented the  
PageRenderListener interface obviously) and it seems to work great. 
Another thing I noticed was that when I debugged inside the listener 
method of the MenuComponent, I saw that when the page was instantiated 
with cycle.getPage(), the control seemed to shift immediately to the new 
page and execute the finishLoad() method. So I guess the record wasn't 
even set when finishLoad() was called on the target page and thus I kept 
getting null pointer exceptions.

Thank you all for your replies and guidance!

Leo

Numa Schmeder wrote:

> Hi,
> You should try to call cycle.activate(page); before setting the 
> property and it should work as expected.
> Because cycle.activate(page); will reset your page properties.
> Thus try this:
>
>> public class MenuComponent extends BaseComponent{
>>    public void loadPage(IRequestCycle cycle){
>>      String page = (String)cycle.getServiceParameters()[0];
>>      RecordClass record = (RecordClass)cycle.getServiceParameters()[1];
>
>          MyPage mpage = cycle.getPage(page);
>
>>       cycle.activate(mpage);
>>       mpage.setProperty("record", record);
>>    }
>> }
>
> Kind regards
> Numa
> On 25 mars 05, at 20:58, Leo Sakhvoruk wrote:
>
>> Hi,
>>
>> I'm fairly new to Tapestry but I have read Howard's book and have 
>> been working on a project using it (Tapestry) for a few weeks. The 
>> issue I'm running up against is as follows.
>>
>> I'm creating a page which includes a menu generating component. This 
>> component requires an array of strings corresponding to page names 
>> and then renders the menu using DirecLinks, each link containing 2 
>> parameters: 1) the name of the page, 2) a record. The component has a 
>> listener that gets invoked when the link is clicked. Now my problem 
>> is that each page renders information contained within the record and 
>> so has to have the record. I was wondering if there is some way, when 
>> the menu component listener is invoked, to set the record for the 
>> page to be activated without having to explicitly instantiate the 
>> page class?
>>
>> I was trying something to the effect of:
>>
>> public class MenuComponent extends BaseComponent{
>>    public void loadPage(IRequestCycle cycle){
>>      String page = (String)cycle.getServiceParameters()[0];
>>      RecordClass record = (RecordClass)cycle.getServiceParameters()[1];
>>
>>       cycle.getPage(page).setProperty("record", record);
>>       cycle.activate(page);
>>    }
>> }
>>
>> Then the target page would have this in it's .page file:
>>
>> <property-specification name="record" type="package.RecordClass" 
>> persistent="no"/>
>>
>> with associated getter and setter methods in the class file.
>>
>> However, when the target page renders the record is null. I'm 
>> guessing here that the setProperty() method is used to set something 
>> other than the <property-specification> of the page, but I wasn't sure.
>>
>> My reason for doing all of this is so that I can dynamically add 
>> links to the menu.
>>
>> Thanks in advance for any direction,
>>
>> Leo
>>
>> ---------------------------------------------------------------------
>> 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: Dynamically setting page properties and invoking pages.

Posted by Numa Schmeder <nu...@euroconsumers.com>.
Hi,
You should try to call cycle.activate(page); before setting the 
property and it should work as expected.
Because cycle.activate(page); will reset your page properties.
Thus try this:
> public class MenuComponent extends BaseComponent{
>    public void loadPage(IRequestCycle cycle){
>      String page = (String)cycle.getServiceParameters()[0];
>      RecordClass record = (RecordClass)cycle.getServiceParameters()[1];
          MyPage mpage = cycle.getPage(page);
>       cycle.activate(mpage);
>       mpage.setProperty("record", record);
>    }
> }
Kind regards
Numa
On 25 mars 05, at 20:58, Leo Sakhvoruk wrote:

> Hi,
>
> I'm fairly new to Tapestry but I have read Howard's book and have been 
> working on a project using it (Tapestry) for a few weeks. The issue 
> I'm running up against is as follows.
>
> I'm creating a page which includes a menu generating component. This 
> component requires an array of strings corresponding to page names and 
> then renders the menu using DirecLinks, each link containing 2 
> parameters: 1) the name of the page, 2) a record. The component has a 
> listener that gets invoked when the link is clicked. Now my problem is 
> that each page renders information contained within the record and so 
> has to have the record. I was wondering if there is some way, when the 
> menu component listener is invoked, to set the record for the page to 
> be activated without having to explicitly instantiate the page class?
>
> I was trying something to the effect of:
>
> public class MenuComponent extends BaseComponent{
>    public void loadPage(IRequestCycle cycle){
>      String page = (String)cycle.getServiceParameters()[0];
>      RecordClass record = (RecordClass)cycle.getServiceParameters()[1];
>
>       cycle.getPage(page).setProperty("record", record);
>       cycle.activate(page);
>    }
> }
>
> Then the target page would have this in it's .page file:
>
> <property-specification name="record" type="package.RecordClass" 
> persistent="no"/>
>
> with associated getter and setter methods in the class file.
>
> However, when the target page renders the record is null. I'm guessing 
> here that the setProperty() method is used to set something other than 
> the <property-specification> of the page, but I wasn't sure.
>
> My reason for doing all of this is so that I can dynamically add links 
> to the menu.
>
> Thanks in advance for any direction,
>
> Leo
>
> ---------------------------------------------------------------------
> 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