org.apache.tapestry5.corelib.components.If

Conditionally renders its body.

[JavaDoc]

Component Parameters

NameTypeFlagsDefaultDefault PrefixDescription
elseBlockNOT Allow NullliteralAn alternate Block to render if the test parameter is false. The default, null, means render nothing in that situation.
negatebooleanNOT Allow NullpropOptional parameter to invert the test. If true, then the body is rendered when the test parameter is false (not true).
testbooleanRequired, NOT Allow NullpropIf true, then the body of the If component is rendered. If false, the body is omitted.

Examples

Start.tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
    <body>
        <h1>Welcome!</h1>

        <t:if test="user">
            Welcome back, ${user.firstName}
            <p:else>
                <t:pagelink name="login">Login</t:pagelink> /
                <t:pagelink name="register">Register</t:pagelink>
            </p:else>
        </t:if>
        
        . . .

</html>

Here, the main text is rendered if the user is logged in (the user property will be non-null after the user logs in). Otherwise, links to a login and register page are rendered.

Notes

Tapestry has many builtin coercions to boolean:

String
True if non-blank and not the literal string "false" (case insensitive)
Number
True if non-zero
Collection
True if non-empty
Object
True (as long as its not null)

Back to index