Class If
java.lang.Object
org.apache.tapestry5.corelib.base.AbstractConditional
org.apache.tapestry5.corelib.components.If
Conditionally renders its body. May render its tag and any informal parameters.
| Name | Type | Flags | Default | Default Prefix |
|---|---|---|---|---|
| else | org. | literal | ||
| An alternate org.apache.tapestry5.Block to render if #test() is false. The default, null, means render nothing in that situation. | ||||
| negate | boolean | prop | ||
| Optional parameter to invert the test. If true, then the body is rendered when the test parameter is false (not true). | ||||
| test | boolean | Required | prop | |
| If true, then the body of the If component is rendered. If false, the body is omitted. | ||||
| then | org. | literal | ||
| The org.apache.tapestry5.Block to render if #test() is true. The default, null, means render the component body in that situation.. | ||||
Examples
Start.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<body>
<h1>Welcome!</h1>
<t:if test="user">
Welcome back, ${user.firstName}
<p:else>
<t:pagelink page="login">Login</t:pagelink> /
<t:pagelink page="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 built in 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 it's not null)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleantest()Performs the test via the parameters; return true to render the body of the component, false to render the else block (or nothing).
-
Constructor Details
-
If
public If()
-
-
Method Details
-
test
Description copied from class:AbstractConditionalPerforms the test via the parameters; return true to render the body of the component, false to render the else block (or nothing).- Specified by:
testin classAbstractConditional- Returns:
- test parameter (if negate is false), or test parameter inverted (if negate is true)
-