FileDocCategorySizeDatePackage
If.javaAPI DocExample2935Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

If

public class If extends Component

Perform basic condition flow. 'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else' Tag.

  • test* (Boolean) - Logic to determined if body of tag is to be displayed

<s:if test="%{false}">
<div>Will Not Be Executed</div>
</s:if>
<s:elseif test="%{true}">
<div>Will Be Executed</div>
</s:elseif>
<s:else>
<div>Will Not Be Executed</div>
</s:else>

see
Else
see
ElseIf

Fields Summary
public static final String
ANSWER
Boolean
answer
String
test
Constructors Summary
public If(com.opensymphony.xwork2.util.ValueStack stack)

        super(stack);
    
Methods Summary
public booleanend(java.io.Writer writer, java.lang.String body)

        stack.getContext().put(ANSWER, answer);
        return super.end(writer, body);
    
public voidsetTest(java.lang.String test)

        this.test = test;
    
public booleanstart(java.io.Writer writer)

        answer = (Boolean) findValue(test, Boolean.class);

        if (answer == null) {
            answer = Boolean.FALSE;
        }
        stack.getContext().put(ANSWER, answer);
        return answer.booleanValue();