Jakarta > Tapestry
Jakarta
 
Font size:      

Conditional

Causes the rendering of a part of an HTML template to occur only if a specified condition is met. The conditionalized part of the template can be a single emulated element (if the element parameter is supplied), the body of the component, or both.

See also: org.apache.tapestry.components.Conditional, If, Else

Warning
This component has been deprecated; Tapestry 4.0 adds the If component which allows conditionalized elements to be safely contained by Form components.

Parameters

Name Type Direction Required Default Description
condition boolean in yes The condition to evaluate.
invert boolean in no false If true, inverts the condition, so that a false condition causes the content to be included. If false (the default), then the condition is evaluated normally. Note: it is easier to specify the "!" operator in the condition's OGNL expression.
element string in no   If specified and condition is satisfied, then the component behaves like an Any, emitting an open and close tag. Informal parameters are applied to the tag. If no element is specified, informal parameters are ignored.

Body: allowed

Informal parameters: allowed

Reserved parameters: none

Examples

The Conditional component in this example is used to display whether the person is a manager, and if they are a manager, whether they have any staff:

EnquiryPage.html:

<span jwcid="@Insert" value="ognl:fullName"/>
<span jwcid="@Conditional" condition="ognl:manager"> is a Manager
 <span jwcid="@Conditional" condition="ognl:! staffList.empty"> with staff.</span>
 <span jwcid="@Conditional" condition="ognl:staffList.empty"> with <font color="red"><b>no</b></font> staff.</span>
</span>
<span jwcid="@Conditional" condition="ognl:! manager"> is not a Manager.</span>

EnquiryPage.java:

public abstract class EnquiryPage extends BasePage {

    public abstract String getFullName();
    public abstract void setFullName(String value);

    public abstract boolean isManager();
    public abstract void setManager(boolean value);

    public abstract List getStaffList();
    public abstract void setStaffList(List value);
}