1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.component; |
20 | |
|
21 | |
import javax.el.MethodExpression; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
import javax.faces.el.MethodBinding; |
24 | |
import javax.faces.event.AbortProcessingException; |
25 | |
import javax.faces.event.ActionEvent; |
26 | |
import javax.faces.event.ActionListener; |
27 | |
import javax.faces.event.FacesEvent; |
28 | |
import javax.faces.event.PhaseId; |
29 | |
|
30 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent; |
31 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFListener; |
32 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
@JSFComponent(defaultRendererType = "javax.faces.Button") |
40 | |
public class UICommand extends UIComponentBase implements ActionSource2 |
41 | |
{ |
42 | |
public static final String COMPONENT_TYPE = "javax.faces.Command"; |
43 | |
public static final String COMPONENT_FAMILY = "javax.faces.Command"; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public UICommand() |
49 | 38 | { |
50 | 38 | setRendererType("javax.faces.Button"); |
51 | 38 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public MethodBinding getAction() |
71 | |
{ |
72 | 0 | MethodExpression actionExpression = getActionExpression(); |
73 | 0 | if (actionExpression instanceof _MethodBindingToMethodExpression) |
74 | |
{ |
75 | 0 | return ((_MethodBindingToMethodExpression) actionExpression) |
76 | |
.getMethodBinding(); |
77 | |
} |
78 | 0 | if (actionExpression != null) |
79 | |
{ |
80 | 0 | return new _MethodExpressionToMethodBinding(actionExpression); |
81 | |
} |
82 | 0 | return null; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void setAction(MethodBinding action) |
89 | |
{ |
90 | 0 | if (action != null) |
91 | |
{ |
92 | 0 | setActionExpression(new _MethodBindingToMethodExpression(action)); |
93 | |
} |
94 | |
else |
95 | |
{ |
96 | 0 | setActionExpression(null); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
public void broadcast(FacesEvent event) throws AbortProcessingException |
102 | |
{ |
103 | 58 | super.broadcast(event); |
104 | |
|
105 | 58 | if (event instanceof ActionEvent) |
106 | |
{ |
107 | 58 | FacesContext context = getFacesContext(); |
108 | |
|
109 | 58 | MethodBinding mb = getActionListener(); |
110 | 58 | if (mb != null) |
111 | |
{ |
112 | 0 | mb.invoke(context, new Object[] |
113 | |
{ event }); |
114 | |
} |
115 | |
|
116 | 58 | ActionListener defaultActionListener = context.getApplication() |
117 | |
.getActionListener(); |
118 | 58 | if (defaultActionListener != null) |
119 | |
{ |
120 | 58 | defaultActionListener.processAction((ActionEvent) event); |
121 | |
} |
122 | |
} |
123 | 58 | } |
124 | |
|
125 | |
@Override |
126 | |
public void queueEvent(FacesEvent event) |
127 | |
{ |
128 | 62 | if (event != null && event instanceof ActionEvent) |
129 | |
{ |
130 | 62 | UIComponent component = event.getComponent(); |
131 | 62 | if (component instanceof ActionSource) |
132 | |
{ |
133 | 62 | if (((ActionSource)component).isImmediate()) |
134 | |
{ |
135 | 0 | event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); |
136 | |
} |
137 | |
else |
138 | |
{ |
139 | 62 | event.setPhaseId(PhaseId.INVOKE_APPLICATION); |
140 | |
} |
141 | |
} |
142 | |
} |
143 | 62 | super.queueEvent(event); |
144 | 62 | } |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
@JSFProperty |
156 | |
public boolean isImmediate() |
157 | |
{ |
158 | 62 | return (Boolean) getStateHelper().eval(PropertyKeys.immediate, Boolean.FALSE); |
159 | |
} |
160 | |
|
161 | |
public void setImmediate(boolean immediate) |
162 | |
{ |
163 | 0 | getStateHelper().put(PropertyKeys.immediate, immediate ); |
164 | 0 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
@JSFProperty |
170 | |
public Object getValue() |
171 | |
{ |
172 | 0 | return getStateHelper().eval(PropertyKeys.value); |
173 | |
} |
174 | |
|
175 | |
public void setValue(Object value) |
176 | |
{ |
177 | 0 | getStateHelper().put(PropertyKeys.value, value ); |
178 | 0 | } |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
@JSFProperty(stateHolder=true, returnSignature = "java.lang.Object", jspName = "action", clientEvent="action") |
194 | |
public MethodExpression getActionExpression() |
195 | |
{ |
196 | 0 | return (MethodExpression) getStateHelper().eval(PropertyKeys.actionExpression); |
197 | |
} |
198 | |
|
199 | |
public void setActionExpression(MethodExpression actionExpression) |
200 | |
{ |
201 | 0 | getStateHelper().put(PropertyKeys.actionExpression, actionExpression); |
202 | 0 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
@JSFProperty(stateHolder=true, returnSignature = "void", methodSignature = "javax.faces.event.ActionEvent") |
214 | |
public MethodBinding getActionListener() |
215 | |
{ |
216 | 58 | return (MethodBinding) getStateHelper().eval(PropertyKeys.actionListener); |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
@JSFProperty(returnSignature="void",methodSignature="javax.faces.event.ActionEvent") |
223 | |
public void setActionListener(MethodBinding actionListener) |
224 | |
{ |
225 | 0 | getStateHelper().put(PropertyKeys.actionListener, actionListener); |
226 | 0 | } |
227 | |
|
228 | |
public void addActionListener(ActionListener listener) |
229 | |
{ |
230 | 4 | addFacesListener(listener); |
231 | 4 | } |
232 | |
|
233 | |
public void removeActionListener(ActionListener listener) |
234 | |
{ |
235 | 0 | removeFacesListener(listener); |
236 | 0 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
@JSFListener(event="javax.faces.event.ActionEvent", |
244 | |
phases="Invoke Application, Apply Request Values") |
245 | |
public ActionListener[] getActionListeners() |
246 | |
{ |
247 | 0 | return (ActionListener[]) getFacesListeners(ActionListener.class); |
248 | |
} |
249 | |
|
250 | 10 | enum PropertyKeys |
251 | |
{ |
252 | 2 | immediate |
253 | 2 | , value |
254 | 2 | , actionExpression |
255 | 2 | , actionListener |
256 | |
} |
257 | |
|
258 | |
@Override |
259 | |
public String getFamily() |
260 | |
{ |
261 | 8 | return COMPONENT_FAMILY; |
262 | |
} |
263 | |
} |