1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.web;
20
21 import net.wotonomy.foundation.NSDictionary;
22
23 /***
24 * WOConditional renders whatever is inside its opening and closing tags
25 * only if a condition is met.
26 * Bindings are:
27 * <ul>
28 * <li>condition: a boolean property that indicates whether the contents of the element
29 * should be displayed, invoked, or passed the request form values.</li>
30 * <li>negate: if this is true, then the behavior of the element is reversed, showing its
31 * contents only if the condition is NOT met.</li>
32 * </ul>
33 *
34 * @author ezamudio@nasoft.com
35 * @author $Author: cgruber $
36 * @version $Revision: 893 $
37 */
38 public class WOConditional extends WODynamicElement {
39
40 public boolean condition;
41 public boolean negate;
42
43 protected WOConditional() {
44 super();
45 }
46
47 public WOConditional(String aName, NSDictionary aMap, WOElement template) {
48 super(aName, aMap, template);
49 }
50
51 public void setCondition(boolean value) {
52 condition = value;
53 }
54 public boolean condition() {
55 return condition;
56 }
57
58 public void setNegate(boolean value) {
59 negate = value;
60 }
61 public boolean negate() {
62 return negate;
63 }
64
65 protected void pullValuesFromParent(WOComponent c) {
66 condition = booleanForProperty("condition", c);
67 negate = booleanForProperty("negate", c);
68 }
69
70 public void takeValuesFromRequest(WORequest aRequest, WOContext aContext) {
71 if (rootElement == null)
72 return;
73 pullValuesFromParent(aContext.component());
74 if ((condition && !negate) || (!condition && negate)) {
75 rootElement.takeValuesFromRequest(aRequest, aContext);
76 }
77 }
78
79 public WOActionResults invokeAction(WORequest aRequest, WOContext aContext) {
80 if (rootElement == null)
81 return null;
82 pullValuesFromParent(aContext.component());
83 WOActionResults el = null;
84 if ((condition && !negate) || (!condition && negate)) {
85 el = rootElement.invokeAction(aRequest, aContext);
86 }
87 return el;
88 }
89
90 public void appendToResponse(WOResponse aResponse, WOContext aContext) {
91 if (rootElement == null)
92 return;
93 pullValuesFromParent(aContext.component());
94 if ((condition && !negate) || (!condition && negate)) {
95 rootElement.appendToResponse(aResponse, aContext);
96 }
97 }
98
99 }