FileDocCategorySizeDatePackage
ElseIf.javaAPI DocExample3299Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

ElseIf

public class ElseIf 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>

Fields Summary
protected Boolean
answer
protected String
test
Constructors Summary
public ElseIf(com.opensymphony.xwork2.util.ValueStack stack)

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

        if (answer == null) {
            answer = Boolean.FALSE;
        }
        if (answer.booleanValue()) {
            stack.getContext().put(If.ANSWER, answer);
        }
        return super.end(writer, "");
    
public voidsetTest(java.lang.String test)

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

        Boolean ifResult = (Boolean) stack.getContext().get(If.ANSWER);

        if ((ifResult == null) || (ifResult.booleanValue())) {
            return false;
        }

        //make the comparision
        answer = (Boolean) findValue(test, Boolean.class);

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