This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Skip to end of metadata
Go to start of metadata

Please make sure you have read the Tag Syntax document and understand how tag attribute syntax works.

Description

Perform basic condition flow. 'If' tag could be used by itself or can be followed by zero or more 'Else if' Tags followed by zero or one 'Else' Tag.

Parameters

{snippet:id=tagattributes|javadoc=false|url=struts2-tags/if.html}

Examples

{snippet:id=example|lang=xml|javadoc=true|url=struts2/core/src/main/java/org/apache/struts2/components/If.java}
  • No labels

2 Comments

  1. when you test a string which has only one char (or more, I haven't tested), you should use double quotes instead of single quote, because it will cause error:

    Caught an exception while evaluating expression 'wed == 'Y'' against value stack
    java.lang.NumberFormatException: For input string: "N"

    Solution: change single quote to double quotes
    Before:
    <s:iterator value="meetings">
    <s:if test="%

    Unknown macro: {wed == 'Y'}

    ">XXXWeeeednesday</s:if>bbb<br>
    </s:iterator>
    After:
    <s:iterator value="meetings">
    <s:if test='%

    Unknown macro: {wed == "Y"}

    '>XXXWeeeednesday</s:if>bbb<br>
    </s:iterator>

    Reference: http://openfre.spaces.live.com/blog/cns!577CB612A686934B!355.entry

    http://mail-archives.apache.org/mod_mbox/struts-user/200802.mbox/%3C15722468.post@talk.nabble.com%3E

    Root cause:
    Quote:
    newton.dave wrote:
    >
    > IIRC a single-character in single quotes will evaluate to a character, not
    > a
    > string. Not entirely sure I get the exception without looking at the
    > source.

    1. This is in the FAQ and other places in the documentation.

      Multiple characters can be placed in single-quotes; it's only when it's a single character in single quotes.