1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.myfaces.trinidad.component;
23
24 import javax.el.MethodExpression;
25 import javax.faces.component.ActionSource;
26 import javax.faces.component.ActionSource2;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.MethodBinding;
29 import javax.faces.event.AbortProcessingException;
30 import javax.faces.event.ActionEvent;
31 import javax.faces.event.ActionListener;
32 import javax.faces.event.FacesEvent;
33 import javax.faces.event.PhaseId;
34 import org.apache.myfaces.trinidad.bean.FacesBean;
35 import org.apache.myfaces.trinidad.bean.PropertyKey;
36 import org.apache.myfaces.trinidad.context.RequestContext;
37 import org.apache.myfaces.trinidad.event.LaunchEvent;
38 import org.apache.myfaces.trinidad.event.ReturnEvent;
39 import org.apache.myfaces.trinidad.event.ReturnListener;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 public class UIXSelectInput extends UIXEditableValue
80 implements ActionSource2,
81 ActionSource
82 {
83 static public final FacesBean.Type TYPE = new FacesBean.Type(
84 UIXEditableValue.TYPE);
85 static public final PropertyKey ACTION_EXPRESSION_KEY =
86 TYPE.registerKey("actionExpression", MethodExpression.class, PropertyKey.CAP_STATE_HOLDER);
87 static public final PropertyKey ACTION_LISTENER_KEY =
88 TYPE.registerKey("actionListener", MethodBinding.class, PropertyKey.CAP_NOT_BOUND | PropertyKey.CAP_STATE_HOLDER);
89 static public final PropertyKey RETURN_LISTENER_KEY =
90 TYPE.registerKey("returnListener", MethodExpression.class);
91
92 static public final String COMPONENT_FAMILY =
93 "org.apache.myfaces.trinidad.SelectInput";
94 static public final String COMPONENT_TYPE =
95 "org.apache.myfaces.trinidad.SelectInput";
96
97
98
99
100 public UIXSelectInput()
101 {
102 super("org.apache.myfaces.trinidad.Text");
103 }
104
105
106 @Deprecated
107 public void setReturnListener(MethodBinding binding)
108 {
109 setReturnListener(adaptMethodBinding(binding));
110 }
111
112 public MethodBinding getAction()
113 {
114 MethodExpression me = getActionExpression();
115 if (me == null)
116 return null;
117
118 if (me instanceof MethodBindingMethodExpression)
119 return ((MethodBindingMethodExpression) me).getMethodBinding();
120
121 return new MethodExpressionMethodBinding(me);
122 }
123
124 public void setAction(MethodBinding binding)
125 {
126 if (binding instanceof MethodExpressionMethodBinding)
127 setActionExpression(((MethodExpressionMethodBinding) binding).getMethodExpression());
128 else
129 setActionExpression(new MethodBindingMethodExpression(binding));
130 }
131
132
133
134
135
136 @Override
137 public void queueEvent(FacesEvent e)
138 {
139 if (e instanceof ActionEvent)
140 {
141
142
143 {
144 e.setPhaseId(PhaseId.ANY_PHASE);
145 }
146
147
148
149
150
151 }
152
153 super.queueEvent(e);
154 }
155
156
157
158
159
160 @Override
161 public void broadcast(FacesEvent event) throws AbortProcessingException
162 {
163 if (event instanceof ActionEvent)
164 {
165 RequestContext afContext = RequestContext.getCurrentInstance();
166 afContext.getDialogService().setCurrentLaunchSource(this);
167
168 try
169 {
170
171 super.broadcast(event);
172
173
174
175 broadcastToMethodBinding(event, getActionListener());
176
177 FacesContext context = getFacesContext();
178 ActionListener defaultActionListener =
179 context.getApplication().getActionListener();
180 if (defaultActionListener != null)
181 {
182 defaultActionListener.processAction((ActionEvent) event);
183 }
184 }
185 finally
186 {
187 afContext.getDialogService().setCurrentLaunchSource(null);
188 }
189 }
190 else if (event instanceof LaunchEvent)
191 {
192
193
194
195
196 ((LaunchEvent) event).launchDialog(true);
197 }
198 else if (event instanceof ReturnEvent)
199 {
200 super.broadcast(event);
201
202 broadcastToMethodExpression(event, getReturnListener());
203 Object returnValue = ((ReturnEvent) event).getReturnValue();
204 if (returnValue != null)
205 {
206 setSubmittedValue(returnValue);
207 }
208
209
210
211
212 getFacesContext().renderResponse();
213 }
214 else
215 {
216 super.broadcast(event);
217 }
218 }
219
220
221
222
223
224
225 final public MethodExpression getActionExpression()
226 {
227 return (MethodExpression)getProperty(ACTION_EXPRESSION_KEY);
228 }
229
230
231
232
233
234
235 final public void setActionExpression(MethodExpression actionExpression)
236 {
237 setProperty(ACTION_EXPRESSION_KEY, (actionExpression));
238 }
239
240
241
242
243
244
245 final public MethodBinding getActionListener()
246 {
247 return (MethodBinding)getProperty(ACTION_LISTENER_KEY);
248 }
249
250
251
252
253
254
255 final public void setActionListener(MethodBinding actionListener)
256 {
257 setProperty(ACTION_LISTENER_KEY, (actionListener));
258 }
259
260
261
262
263
264
265 final public MethodExpression getReturnListener()
266 {
267 return (MethodExpression)getProperty(RETURN_LISTENER_KEY);
268 }
269
270
271
272
273
274
275 final public void setReturnListener(MethodExpression returnListener)
276 {
277 setProperty(RETURN_LISTENER_KEY, (returnListener));
278 }
279
280
281
282
283
284
285 final public void addActionListener(
286 ActionListener listener)
287 {
288 addFacesListener(listener);
289 }
290
291
292
293
294
295
296 final public void removeActionListener(
297 ActionListener listener)
298 {
299 removeFacesListener(listener);
300 }
301
302
303
304
305
306
307 final public ActionListener[] getActionListeners()
308 {
309 return (ActionListener[])getFacesListeners(ActionListener.class);
310 }
311
312
313
314
315
316
317 final public void addReturnListener(
318 ReturnListener listener)
319 {
320 addFacesListener(listener);
321 }
322
323
324
325
326
327
328 final public void removeReturnListener(
329 ReturnListener listener)
330 {
331 removeFacesListener(listener);
332 }
333
334
335
336
337
338
339 final public ReturnListener[] getReturnListeners()
340 {
341 return (ReturnListener[])getFacesListeners(ReturnListener.class);
342 }
343
344 @Override
345 public String getFamily()
346 {
347 return COMPONENT_FAMILY;
348 }
349
350 @Override
351 protected FacesBean.Type getBeanType()
352 {
353 return TYPE;
354 }
355
356
357
358
359 protected UIXSelectInput(
360 String rendererType
361 )
362 {
363 super(rendererType);
364 }
365
366 static
367 {
368 TYPE.lockAndRegister("org.apache.myfaces.trinidad.SelectInput","org.apache.myfaces.trinidad.Text");
369 }
370 }