1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts.ui.common.tag;
20
21 import javax.faces.FacesException;
22 import javax.faces.component.UICommand;
23 import javax.faces.component.UIComponent;
24 import javax.faces.el.MethodBinding;
25 import javax.faces.el.ValueBinding;
26 import javax.faces.webapp.UIComponentTag;
27
28 import org.springframework.extensions.webscripts.ui.common.ConstantMethodBinding;
29
30
31
32
33 public abstract class BaseComponentTag extends UIComponentTag
34 {
35
36
37
38
39
40
41 protected void setActionProperty(UICommand command, String action)
42 {
43 if (action != null)
44 {
45 if (isValueReference(action))
46 {
47 MethodBinding vb = getFacesContext().getApplication().createMethodBinding(action, null);
48 command.setAction(vb);
49 }
50 else
51 {
52 MethodBinding vb = new ConstantMethodBinding(action);
53 command.setAction(vb);
54 }
55 }
56 }
57
58
59
60
61
62
63
64 protected void setActionListenerProperty(UICommand command, String actionListener)
65 {
66 if (actionListener != null)
67 {
68 if (isValueReference(actionListener))
69 {
70 MethodBinding vb = getFacesContext().getApplication().createMethodBinding(actionListener, ACTION_CLASS_ARGS);
71 command.setActionListener(vb);
72 }
73 else
74 {
75 throw new FacesException("Action listener method binding incorrectly specified: " + actionListener);
76 }
77 }
78 }
79
80
81
82
83
84
85
86
87
88 protected void setStringProperty(UIComponent component, String name, String value)
89 {
90 if (value != null)
91 {
92 if (isValueReference(value))
93 {
94 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value);
95 component.setValueBinding(name, vb);
96 }
97 else
98 {
99 component.getAttributes().put(name, value);
100 }
101 }
102 }
103
104
105
106
107
108
109
110
111
112 protected void setStringBindingProperty(UIComponent component, String name, String value)
113 {
114 if (value != null)
115 {
116 if (isValueReference(value))
117 {
118 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value);
119 component.setValueBinding(name, vb);
120 }
121 else
122 {
123 throw new IllegalArgumentException("Property: '" + name + "' must be a value binding expression.");
124 }
125 }
126 }
127
128
129
130
131
132
133
134
135
136 protected void setStringStaticProperty(UIComponent component, String name, String value)
137 {
138 if (value != null)
139 {
140 component.getAttributes().put(name, value);
141 }
142 }
143
144
145
146
147
148
149
150
151
152 protected void setIntProperty(UIComponent component, String name, String value)
153 {
154 if (value != null)
155 {
156 if (isValueReference(value))
157 {
158 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value);
159 component.setValueBinding(name, vb);
160 }
161 else
162 {
163 try
164 {
165 component.getAttributes().put(name, Integer.valueOf(value));
166 }
167 catch (NumberFormatException ne)
168 {
169 throw new RuntimeException("Was expecting Int value for property '" + name + "' but passed value: " + value);
170 }
171 }
172 }
173 }
174
175 protected void setIntStaticProperty(UIComponent component, String name, String value)
176 {
177 if (value != null)
178 {
179 try
180 {
181 component.getAttributes().put(name, Integer.valueOf(value));
182 }
183 catch (NumberFormatException ne)
184 {
185 throw new RuntimeException("Was expecting Int value for property '" + name + "' but passed value: " + value);
186 }
187 }
188 }
189
190
191
192
193
194
195
196
197
198 protected void setBooleanProperty(UIComponent component, String name, String value)
199 {
200 if (value != null)
201 {
202 if (isValueReference(value))
203 {
204 ValueBinding vb = getFacesContext().getApplication().createValueBinding(value);
205 component.setValueBinding(name, vb);
206 }
207 else
208 {
209 component.getAttributes().put(name, Boolean.valueOf(value));
210 }
211 }
212 }
213
214 protected void setBooleanStaticProperty(UIComponent component, String name, String value)
215 {
216 if (value != null)
217 {
218 component.getAttributes().put(name, Boolean.valueOf(value));
219 }
220 }
221
222 protected final static Class ACTION_CLASS_ARGS[] = {javax.faces.event.ActionEvent.class};
223 }