View Javadoc

1   // WARNING: This file was automatically generated. Do not edit it directly,
2   //          or you will lose your changes.
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
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   * selectInput is a base abstraction for
44   *           components that allow both input and selection 
45   *           from a list of possible values.
46   *
47   * <h4>Events:</h4>
48   * <table border="1" width="100%" cellpadding="3" summary="">
49   * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
50   * <th align="left">Type</th>
51   * <th align="left">Phases</th>
52   * <th align="left">Description</th>
53   * </tr>
54   * <tr class="TableRowColor">
55   * <td valign="top"><code>javax.faces.event.ActionEvent</code></td>
56   * <td valign="top" nowrap>Apply<br>Request<br>Values</td>
57   * <td valign="top">Event delivered when the "action" of the component has been
58  invoked;  for example, by clicking on a button.  The action may result
59  in page navigation.</td>
60   * </tr>
61   * <tr class="TableRowColor">
62   * <td valign="top"><code>org.apache.myfaces.trinidad.event.ReturnEvent</code></td>
63   * <td valign="top" nowrap>Apply<br>Request<br>Values</td>
64   * <td valign="top">Event delivered when the dialog has completed successfully.</td>
65   * </tr>
66   * <tr class="TableRowColor">
67   * <td valign="top"><code>javax.faces.event.ValueChangeEvent</code></td>
68   * <td valign="top" nowrap>Process<br>Validations<br>Apply<br>Request<br>Values</td>
69   * <td valign="top">The valueChange event is delivered when the value
70                         attribute is changed.</td>
71   * </tr>
72   * <tr class="TableRowColor">
73   * <td valign="top"><code>org.apache.myfaces.trinidad.event.AttributeChangeEvent</code></td>
74   * <td valign="top" nowrap>Invoke<br>Application<br>Apply<br>Request<br>Values</td>
75   * <td valign="top">Event delivered to describe an attribute change.  Attribute change events are not delivered for any programmatic change to a property.  They are only delivered when a renderer changes a property without the application's specific request.  An example of an attribute change event might include the width of a column that supported client-side resizing.</td>
76   * </tr>
77   * </table>
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     * Construct an instance of the UIXSelectInput.
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    * <p>Intercept <code>queueEvent</code> and mark the phaseId for any
134    * ActionEvents to be <code>PhaseId.APPLY_REQUEST_VALUES</code>.
135    */
136   @Override
137   public void queueEvent(FacesEvent e)
138   {
139     if (e instanceof ActionEvent)
140     {
141       // Always deliver ActionEvents immediately?
142       //  if (isImmediate())
143       {
144         e.setPhaseId(PhaseId.ANY_PHASE);
145       }
146       /*
147       else
148       {
149         e.setPhaseId(PhaseId.INVOKE_APPLICATION);
150         }*/
151     }
152 
153     super.queueEvent(e);
154   }
155 
156 
157   /**
158    * {@inheritDoc}
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         // Perform standard superclass processing
171         super.broadcast(event);
172 
173         // Notify the specified action listener method (if any),
174         // and the default action listener
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       // =-=AEW Support launch listeners on SelectInput?
193       // super.broadcast(event);
194       //
195       // __broadcast(event, getLaunchListener());
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       // =-=AEW: always jump to render response???  Seems the safest
210       // option, because we don't want to immediately update a model
211       // or really perform any validation.
212       getFacesContext().renderResponse();
213     }
214     else
215     {
216       super.broadcast(event);
217     }
218   }
219 
220   /**
221    * Gets a reference to an action method sent by the commandButton, or the static outcome of an action
222    *
223    * @return  the new actionExpression value
224    */
225   final public MethodExpression getActionExpression()
226   {
227     return (MethodExpression)getProperty(ACTION_EXPRESSION_KEY);
228   }
229 
230   /**
231    * Sets a reference to an action method sent by the commandButton, or the static outcome of an action
232    * 
233    * @param actionExpression  the new actionExpression value
234    */
235   final public void setActionExpression(MethodExpression actionExpression)
236   {
237     setProperty(ACTION_EXPRESSION_KEY, (actionExpression));
238   }
239 
240   /**
241    * Gets a method reference to an action listener
242    *
243    * @return  the new actionListener value
244    */
245   final public MethodBinding getActionListener()
246   {
247     return (MethodBinding)getProperty(ACTION_LISTENER_KEY);
248   }
249 
250   /**
251    * Sets a method reference to an action listener
252    * 
253    * @param actionListener  the new actionListener value
254    */
255   final public void setActionListener(MethodBinding actionListener)
256   {
257     setProperty(ACTION_LISTENER_KEY, (actionListener));
258   }
259 
260   /**
261    * Gets a method reference to an return listener
262    *
263    * @return  the new returnListener value
264    */
265   final public MethodExpression getReturnListener()
266   {
267     return (MethodExpression)getProperty(RETURN_LISTENER_KEY);
268   }
269 
270   /**
271    * Sets a method reference to an return listener
272    * 
273    * @param returnListener  the new returnListener value
274    */
275   final public void setReturnListener(MethodExpression returnListener)
276   {
277     setProperty(RETURN_LISTENER_KEY, (returnListener));
278   }
279 
280   /**
281    * Adds a action listener.
282    *
283    * @param listener  the action listener to add
284    */
285   final public void addActionListener(
286     ActionListener listener)
287   {
288     addFacesListener(listener);
289   }
290 
291   /**
292    * Removes a action listener.
293    *
294    * @param listener  the action listener to remove
295    */
296   final public void removeActionListener(
297     ActionListener listener)
298   {
299     removeFacesListener(listener);
300   }
301 
302   /**
303    * Returns an array of attached action listeners.
304    *
305    * @return  an array of attached action listeners.
306    */
307   final public ActionListener[] getActionListeners()
308   {
309     return (ActionListener[])getFacesListeners(ActionListener.class);
310   }
311 
312   /**
313    * Adds a return listener.
314    *
315    * @param listener  the return listener to add
316    */
317   final public void addReturnListener(
318     ReturnListener listener)
319   {
320     addFacesListener(listener);
321   }
322 
323   /**
324    * Removes a return listener.
325    *
326    * @param listener  the return listener to remove
327    */
328   final public void removeReturnListener(
329     ReturnListener listener)
330   {
331     removeFacesListener(listener);
332   }
333 
334   /**
335    * Returns an array of attached return listeners.
336    *
337    * @return  an array of attached return listeners.
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    * Construct an instance of the UIXSelectInput.
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 }