You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by gvp <bl...@gmail.com> on 2005/03/29 18:09:51 UTC

Conditional component rendering

Hi All,

I have 2 components A and B implementing PageRenderListener interface.
Each component has initialization code in the method pageBeginRender.
I place A and B at a page and want to render only one component at the time. To
achieve this the following template is used:

<span jwcid="@Conditional" condition="ognl:showA">
    <span jwcid="@A"/>
</span>
<span jwcid="@Conditional" condition="ognl:showB">
    <span jwcid="@B"/>
</span>

Everything works fine - only one component is visible. But
A.pageBeginRender and B.pageBeginRender are executed each time
regardless of which component is visible.

Question:
  How to conditionally place components A and B so that only one
  component is visible and only one pageBeginRender method is
  executed. Or if it's not possible: where should I place component
  initialization code to achieve this goal?
  

-- 
Best regards,
gvp                          


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


Re: Conditional component rendering

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Another option is to do things lazily..... pageBeginRender doesn't need 
to be the place to do an expensive or unnecessary operation.

	Erik

On Mar 29, 2005, at 2:59 PM, Bryan Lewis wrote:

> A similar question came up last Thursday, and the answer worked for 
> me.  One
> solution, as Eirk suggested, is to give the component a 'disabled'
> parameter.  But Kent Tong's suggestion is easier:
>
>     Would overriding AbstractComponent.prepareForRender() work
>     for you? It will be called just before your component is
>     rendered. If the component is not rendered, it will not
>     be called.
>
> In other words, pageBeginRender() is called on every component at the 
> start
> of the page rendering.  prepareForRender() is called only on 
> components that
> are actually rendered.
>
>
> ----- Original Message -----
> From: "gvp" <bl...@gmail.com>
> To: <ta...@jakarta.apache.org>
> Sent: Tuesday, March 29, 2005 11:09 AM
> Subject: Conditional component rendering
>
>
>> Hi All,
>>
>> I have 2 components A and B implementing PageRenderListener interface.
>> Each component has initialization code in the method pageBeginRender.
>> I place A and B at a page and want to render only one component at the
> time. To
>> achieve this the following template is used:
>>
>> <span jwcid="@Conditional" condition="ognl:showA">
>>     <span jwcid="@A"/>
>> </span>
>> <span jwcid="@Conditional" condition="ognl:showB">
>>     <span jwcid="@B"/>
>> </span>
>>
>> Everything works fine - only one component is visible. But
>> A.pageBeginRender and B.pageBeginRender are executed each time
>> regardless of which component is visible.
>>
>> Question:
>>   How to conditionally place components A and B so that only one
>>   component is visible and only one pageBeginRender method is
>>   executed. Or if it's not possible: where should I place component
>>   initialization code to achieve this goal?
>>
>>
>> -- 
>> Best regards,
>> gvp
>>
>>
>> ---------------------------------------------------------------------
>> 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: Conditional component rendering

Posted by Bryan Lewis <br...@maine.rr.com>.
A similar question came up last Thursday, and the answer worked for me.  One
solution, as Eirk suggested, is to give the component a 'disabled'
parameter.  But Kent Tong's suggestion is easier:

    Would overriding AbstractComponent.prepareForRender() work
    for you? It will be called just before your component is
    rendered. If the component is not rendered, it will not
    be called.

In other words, pageBeginRender() is called on every component at the start
of the page rendering.  prepareForRender() is called only on components that
are actually rendered.


----- Original Message ----- 
From: "gvp" <bl...@gmail.com>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, March 29, 2005 11:09 AM
Subject: Conditional component rendering


> Hi All,
>
> I have 2 components A and B implementing PageRenderListener interface.
> Each component has initialization code in the method pageBeginRender.
> I place A and B at a page and want to render only one component at the
time. To
> achieve this the following template is used:
>
> <span jwcid="@Conditional" condition="ognl:showA">
>     <span jwcid="@A"/>
> </span>
> <span jwcid="@Conditional" condition="ognl:showB">
>     <span jwcid="@B"/>
> </span>
>
> Everything works fine - only one component is visible. But
> A.pageBeginRender and B.pageBeginRender are executed each time
> regardless of which component is visible.
>
> Question:
>   How to conditionally place components A and B so that only one
>   component is visible and only one pageBeginRender method is
>   executed. Or if it's not possible: where should I place component
>   initialization code to achieve this goal?
>
>
> -- 
> Best regards,
> gvp
>
>
> ---------------------------------------------------------------------
> 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: Conditional component rendering

Posted by gvp <bl...@gmail.com>.
Hello gvp,

Thank you for advise, AbstractComponent.prepareForRender is working
for me.

>Would overriding AbstractComponent.prepareForRender() work
>    for you? It will be called just before your component is
>    rendered. If the component is not rendered, it will not
>    be called.
>   initialization code to achieve this goal?
  



-- 
Best regards,
gvp                            


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


Re: Conditional component rendering

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
What about folding conditional capabilities into components A and B 
instead of using Conditional around it?

	Erik


On Mar 29, 2005, at 11:09 AM, gvp wrote:

> Hi All,
>
> I have 2 components A and B implementing PageRenderListener interface.
> Each component has initialization code in the method pageBeginRender.
> I place A and B at a page and want to render only one component at the 
> time. To
> achieve this the following template is used:
>
> <span jwcid="@Conditional" condition="ognl:showA">
>     <span jwcid="@A"/>
> </span>
> <span jwcid="@Conditional" condition="ognl:showB">
>     <span jwcid="@B"/>
> </span>
>
> Everything works fine - only one component is visible. But
> A.pageBeginRender and B.pageBeginRender are executed each time
> regardless of which component is visible.
>
> Question:
>   How to conditionally place components A and B so that only one
>   component is visible and only one pageBeginRender method is
>   executed. Or if it's not possible: where should I place component
>   initialization code to achieve this goal?
>
>
> -- 
> Best regards,
> gvp
>
>
> ---------------------------------------------------------------------
> 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