Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tapestry5.corelib.components
Class If

    java.lang.Object
      org.apache.tapestry5.corelib.base.AbstractConditional
          org.apache.tapestry5.corelib.components.If

    public class If

extends AbstractConditional

Conditionally renders its body. May render its tag and any informal parameters.

Component Parameters
Name | Description | Type | Flags | Default | Default Prefix | Since
--- | --- | --- | --- | --- | --- | ---
else | An alternate org.apache.tapestry5.Block to render if org.apache.tapestry5.corelib.base.AbstractConditional#test() is false. The default, null, means render nothing in that situation. | org.apache.tapestry5.Block |  |  | literal |
negate | Optional parameter to invert the test. If true, then the body is rendered when the test parameter is false (not true). | boolean |  |  | prop |
test | If true, then the body of the If component is rendered. If false, the body is omitted. | boolean | Required |  | prop |

Examples:

  ### Start.tml

      <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_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.

  Note the use of the `p:` namespace (new in Tapestry 5.1). In 5.0, this would be ``.

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 its not null)

Constructor Summary
`If()`

Method Summary
`protected boolean` | `test()` Performs the test via the parameters; return true to render the body of the component, false to render the else block (or nothing).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### If

    public If()

Method Detail

### test

    protected boolean test()

  Description copied from class: `AbstractConditional`
  Performs the test via the parameters; return true to render the body of the component, false to render the else block (or nothing).

  Specified by:
    `test` in class `AbstractConditional`
  Returns:
    test parameter (if negate is false), or test parameter inverted (if negate is true)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2012 The Apache Software Foundation.