Also, if you would like to put the logic to determine if a component should
display or not in that component, you can have your SetupRender or
BeginRender phases return a boolean result -- if it returns the false, the
component will not be rendered (no matter where that component is placed). 
For example:

Page template:

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
    <head>
        <title>Conditionally render a component</title>
    </head>
    <body>
        <t:myConditionalDisplayComponent />
    </body>
</html>

Component template:

<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
I've been displayed!
</div>

Component class:

package org.example.myapp.components;

import org.apache.tapestry.MarkupWriter;
import org.apache.tapestry.annotations.BeginRender;
import org.example.myapp.services.DetermineSomeCondition;

public class MyConditionalDisplayComponent {
    
    private someCondition;

    @BeginRender
    boolean beginRender() {
        someCondition = DetermineSomeCondition.determine();
        return (someCondition == true);
    }
}

Daniel Jue wrote:
> 
> Hi, I would try blocks of components at the end of your template, and
> a delegate component.
> 
> The delegate refers to a method in your page or component class the
> template it for.  It returns an Object, which is actually one of the
> component blocks. It can also return null and nothing will be rendered
> where the delegate tag was.
> 
> Alternatively, you could wrap a section of code in an If component.
> 
> 
> 
> For instance, to delegate:
> 
> <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
> <tr>
>       <td><t:selectdaterangetype /></td>
> </tr>
> <tr>
>       <td><t:delegate to="typeOfDateRange" /></td>
> </tr>
> 
> <t:block>
>       <t:selectmonth />
>       <t:selectmonthrange />
>       <t:selectquarter />
>       <t:selectquarterrange />
> </t:block></div>
> 
> 
> --------------------------------
> The java:
> 
>       @Component(id = "daterangetypeSelector")
>       private SelectDateRangeType selectdaterangetype;
> 
>       @Component
>       private SelectMonth selectmonth;
> 
>       @Component
>       private SelectMonthRange selectmonthrange;
> 
>       @Component
>       private SelectQuarter selectquarter;
> 
>       @Component
>       private SelectQuarterRange selectquarterrange;
> 
>       public Object getTypeOfDateRange() {
>               DateRangeType drt = selectdaterangetype.getSelected();
>               if (drt.equals(DateRangeTypeEnum.DR_ENTIRE_FISCAL_YEAR)) {
>                       return null;
>               } else if (drt.equals(DateRangeTypeEnum.DR_MONTH_SINGLE)) {
>                       return selectmonth;
>               } else if (drt.equals(DateRangeTypeEnum.DR_MONTH_RANGE)) {
>                       return selectmonthrange;
>               } else if (drt.equals(DateRangeTypeEnum.DR_QUARTER_SINGLE)) {
>                       return selectquarter;
>               } else {
>                       logger.debug("getTypeOfDateRange() DRT is unknown to 
> me, drt="
>                                       + drt.toDisplay());
>                       return null;
>               }
>       }
> 
> 
> 
> 
> 
> On 8/3/07, Janko Muzykant <[EMAIL PROTECTED]> wrote:
>>
>> hello, i would like to omit some part of my page eg. allow only one
>> component
>> to be written in output. i did it writing my own MarkupWriter with
>> enable/disable function which when enabled works as standard writer and
>> when
>> disabled ignores all writings. It's initially disabled and only specific
>> component toggles the flag to write out its body. It works, but having in
>> mind all the flexibility of tapestry 5 i bet there is much better way to
>> do
>> the same thing. Could you enlighten me a bit and suggest better solution?
>>
>> thanks,
>> jm.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/T5-Best-way-to-omit-part-of-result-page-in-output-tf4211016.html#a11978648
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/T5-Best-way-to-omit-part-of-result-page-in-output-tf4211016.html#a11986632
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to