01: package com.opensymphony.webwork.components;
02:
03: import com.opensymphony.xwork.util.OgnlValueStack;
04:
05: import java.io.Writer;
06:
07: /**
08: * <!-- START SNIPPET: javadoc -->
09: *
10: * <p>Perform basic condition flow. 'If' tag could be used by itself or
11: * with 'Else If' Tag and/or single/multiple 'Else' Tag.</p>
12: *
13: * <!-- END SNIPPET: javadoc -->
14: *
15: *
16: * <!-- START SNIPPET: params -->
17: *
18: * <ul>
19: *
20: * <li>test* (Boolean) - Logic to determined if body of tag is to be displayed</li>
21: *
22: * </ul>
23: *
24: * <!-- END SNIPPET: params -->
25: *
26: *
27: * <pre>
28: * <!-- START SNIPPET: example -->
29: * <ww:if test="%{false}">
30: * <div>Will Not Be Executed</div>
31: * </ww:if>
32: * <ww:elseif test="%{true}">
33: * <div>Will Be Executed</div>
34: * </ww:elseif>
35: * <ww:else>
36: * <div>Will Not Be Executed</div>
37: * </ww:else>
38: * <!-- END SNIPPET: example -->
39: * </pre>
40: *
41: * @author tmjee
42: *
43: * @see Else
44: * @see ElseIf
45: *
46: * @ww.tag name="if" tld-body-content="JSP" description="If tag" tld-tag-class="com.opensymphony.webwork.views.jsp.IfTag"
47: */
48: public class If extends Component {
49: public static final String ANSWER = "webwork.if.answer";
50:
51: Boolean answer;
52: String test;
53:
54: /**
55: * Expression to determine if body of tag is to be displayed
56: * @ww.tagattribute required="true" type="Boolean"
57: */
58: public void setTest(String test) {
59: this .test = test;
60: }
61:
62: public If(OgnlValueStack stack) {
63: super (stack);
64: }
65:
66: public boolean start(Writer writer) {
67: answer = (Boolean) findValue(test, Boolean.class);
68:
69: if (answer == null) {
70: answer = Boolean.FALSE;
71: }
72:
73: stack.getContext().put(ANSWER, answer);
74:
75: return answer.booleanValue();
76: }
77:
78: public boolean end(Writer writer, String body) {
79: stack.getContext().put(ANSWER, answer);
80: return super.end(writer, body);
81: }
82: }
|