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.html;
23  
24  import java.util.ArrayDeque;
25  import java.util.Arrays;
26  import java.util.Collection;
27  import java.util.Collections;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Queue;
31  import javax.faces.component.behavior.ClientBehavior;
32  import javax.faces.component.behavior.ClientBehaviorHolder;
33  import javax.faces.context.FacesContext;
34  import org.apache.myfaces.trinidad.bean.FacesBean;
35  import org.apache.myfaces.trinidad.bean.PropertyKey;
36  import org.apache.myfaces.trinidad.component.UIXComponentBase;
37  import org.apache.myfaces.trinidad.context.ComponentContextManager;
38  import org.apache.myfaces.trinidad.context.RequestContext;
39  import org.apache.myfaces.trinidad.context.SuspendedContextChanges;
40  import org.apache.myfaces.trinidad.util.ComponentUtils;
41  
42  /**
43   *
44   * <html:p>
45   *             Tag for the HTML body element.  In addition
46   * to providing support for the standard HTML body functionality,
47   * the Trinidad body component enables partial-page rendering (PPR) support
48   * and assigning initial page focus.
49   *           </html:p>
50   * <html:p>
51   *   The body component resets the Trinidad EL context when code re-enters the component via
52   *   an invoke on component call or a visit tree call. See the
53   *   org.apache.myfaces.trinidad.context.ComponentContextManager for more information.
54   * </html:p>
55   *
56   * <h4>Events:</h4>
57   * <table border="1" width="100%" cellpadding="3" summary="">
58   * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
59   * <th align="left">Type</th>
60   * <th align="left">Phases</th>
61   * <th align="left">Description</th>
62   * </tr>
63   * <tr class="TableRowColor">
64   * <td valign="top"><code>org.apache.myfaces.trinidad.event.AttributeChangeEvent</code></td>
65   * <td valign="top" nowrap>Invoke<br>Application<br>Apply<br>Request<br>Values</td>
66   * <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>
67   * </tr>
68   * </table>
69   */
70  public class HtmlBody extends UIXComponentBase
71                        implements ClientBehaviorHolder
72  {
73    static public final FacesBean.Type TYPE = new FacesBean.Type(
74      UIXComponentBase.TYPE);
75    static public final PropertyKey FIRST_CLICK_PASSED_KEY =
76      TYPE.registerKey("firstClickPassed", Boolean.class, Boolean.FALSE);
77    static public final PropertyKey SHORT_DESC_KEY =
78      TYPE.registerKey("shortDesc", String.class);
79    static public final PropertyKey PARTIAL_TRIGGERS_KEY =
80      TYPE.registerKey("partialTriggers", String[].class, null, 0, PropertyKey.Mutable.RARELY);
81    static public final PropertyKey ONCLICK_KEY =
82      TYPE.registerKey("onclick", String.class);
83    static public final PropertyKey ONDBLCLICK_KEY =
84      TYPE.registerKey("ondblclick", String.class);
85    static public final PropertyKey ONMOUSEDOWN_KEY =
86      TYPE.registerKey("onmousedown", String.class);
87    static public final PropertyKey ONMOUSEUP_KEY =
88      TYPE.registerKey("onmouseup", String.class);
89    static public final PropertyKey ONMOUSEOVER_KEY =
90      TYPE.registerKey("onmouseover", String.class);
91    static public final PropertyKey ONMOUSEMOVE_KEY =
92      TYPE.registerKey("onmousemove", String.class);
93    static public final PropertyKey ONMOUSEOUT_KEY =
94      TYPE.registerKey("onmouseout", String.class);
95    static public final PropertyKey ONKEYPRESS_KEY =
96      TYPE.registerKey("onkeypress", String.class);
97    static public final PropertyKey ONKEYDOWN_KEY =
98      TYPE.registerKey("onkeydown", String.class);
99    static public final PropertyKey ONKEYUP_KEY =
100     TYPE.registerKey("onkeyup", String.class);
101   static public final PropertyKey STYLE_CLASS_KEY =
102     TYPE.registerKey("styleClass", String.class);
103   static public final PropertyKey INLINE_STYLE_KEY =
104     TYPE.registerKey("inlineStyle", String.class);
105   static public final PropertyKey ONLOAD_KEY =
106     TYPE.registerKey("onload", String.class);
107   static public final PropertyKey ONUNLOAD_KEY =
108     TYPE.registerKey("onunload", String.class);
109   static public final PropertyKey INITIAL_FOCUS_ID_KEY =
110     TYPE.registerKey("initialFocusId", String.class);
111 
112   static public final String COMPONENT_FAMILY =
113     "org.apache.myfaces.trinidad.Body";
114   static public final String COMPONENT_TYPE =
115     "org.apache.myfaces.trinidad.HtmlBody";
116   // Supported client events for client behaviors:
117   private final static Collection<String> _EVENT_NAMES = Collections.unmodifiableCollection(
118     Arrays.asList(
119       "click", "dblclick", "mousedown", "mouseup", "mouseover", "mousemove",
120       "mouseout", "keypress", "keydown", "keyup", "load", "unload"
121     ));
122 
123   /**
124    * Construct an instance of the HtmlBody.
125    */
126   public HtmlBody()
127   {
128     super("org.apache.myfaces.trinidad.Body");
129   }
130     /**
131    * Suspends any context changes before allowing invokeOnComponent or visitTree calls to continue,
132    * allowing components to undo any context changes during a re-entrant call.
133    * @param facesContext the faces context
134    * @see ComponentContextManager#suspend(FacesContext)
135    */
136   @Override
137   protected void setupVisitingContext(FacesContext facesContext)
138   {
139     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
140       .getComponentContextManager();
141 
142     // Suspend any current component context during a visit tree for re-entrant
143     // component tree processing
144     SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
145 
146     Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
147     @SuppressWarnings("unchecked")
148     Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
149       reqMap.get(_SUSPENDED_CHANGES_KEY);
150     if (suspendedChangesQueue == null)
151     {
152       suspendedChangesQueue = Collections.asLifoQueue(new ArrayDeque<SuspendedContextChanges>());
153       reqMap.put(_SUSPENDED_CHANGES_KEY, suspendedChangesQueue);
154     }
155 
156     suspendedChangesQueue.offer(suspendedChanges);
157 
158     super.setupVisitingContext(facesContext);
159   }
160 
161   /**
162    * Re-applies the suspended context changes.
163    * @param facesContext the faces context
164    * @see #setupVisitingContext(FacesContext)
165    * @see ComponentContextManager#resume(FacesContext, SuspendedContextChanges)
166    */
167   @Override
168   protected void tearDownVisitingContext(FacesContext facesContext)
169   {
170     super.tearDownVisitingContext(facesContext);
171 
172     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
173       .getComponentContextManager();
174     Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
175     @SuppressWarnings("unchecked")
176     Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
177       reqMap.get(_SUSPENDED_CHANGES_KEY);
178     SuspendedContextChanges changes = suspendedChangesQueue.poll();
179     ctxMgr.resume(facesContext, changes);
180   }
181 
182   private final static String _SUSPENDED_CHANGES_KEY = HtmlBody.class.getName() +
183                                                        ".SUSPENDED_CHANGES";
184 
185   /**
186    * Gets whether or not Trinidad will allow the first click to go
187    *              through in certain instances. When a PPR event occurs, we block
188    *              all subsequent user input until it completes. However, there may
189    *              be instances where the client wants to receive the very first
190    *              click. For example, if the user entered text in an inputText
191    *              that fires a PPR request, then the user immediately clicked
192    *              a submit button two events will be triggered - an onchange
193    *              followed by an onclick. The onchange will trigger the client
194    *              action which will immediately start the PPR blocking, so the
195    *              onclick will get consumed by the blocking code and no submit will
196    *              occur. Setting this value to true will allow the click to go
197    *              through.
198    *
199    * @return  the new firstClickPassed value
200    */
201   final public boolean isFirstClickPassed()
202   {
203     return ComponentUtils.resolveBoolean(getProperty(FIRST_CLICK_PASSED_KEY), false);
204   }
205 
206   /**
207    * Sets whether or not Trinidad will allow the first click to go
208    *              through in certain instances. When a PPR event occurs, we block
209    *              all subsequent user input until it completes. However, there may
210    *              be instances where the client wants to receive the very first
211    *              click. For example, if the user entered text in an inputText
212    *              that fires a PPR request, then the user immediately clicked
213    *              a submit button two events will be triggered - an onchange
214    *              followed by an onclick. The onchange will trigger the client
215    *              action which will immediately start the PPR blocking, so the
216    *              onclick will get consumed by the blocking code and no submit will
217    *              occur. Setting this value to true will allow the click to go
218    *              through.
219    * 
220    * @param firstClickPassed  the new firstClickPassed value
221    */
222   final public void setFirstClickPassed(boolean firstClickPassed)
223   {
224     setProperty(FIRST_CLICK_PASSED_KEY, firstClickPassed ? Boolean.TRUE : Boolean.FALSE);
225   }
226 
227   /**
228    * Gets the short description of the bean.  This text
229    *          is commonly used by user agents to display tooltip help text.
230    *
231    * @return  the new shortDesc value
232    */
233   final public String getShortDesc()
234   {
235     return ComponentUtils.resolveString(getProperty(SHORT_DESC_KEY));
236   }
237 
238   /**
239    * Sets the short description of the bean.  This text
240    *          is commonly used by user agents to display tooltip help text.
241    * 
242    * @param shortDesc  the new shortDesc value
243    */
244   final public void setShortDesc(String shortDesc)
245   {
246     setProperty(SHORT_DESC_KEY, (shortDesc));
247   }
248 
249   /**
250    * Gets the IDs of the components that should trigger a partial update.
251    *          This component will listen on the trigger components. If one of the
252    *          trigger components receives an event that will cause it to update
253    *          in some way, this component will request to be updated too.
254    *
255    * @return  the new partialTriggers value
256    */
257   final public String[] getPartialTriggers()
258   {
259     return (String[])getProperty(PARTIAL_TRIGGERS_KEY);
260   }
261 
262   /**
263    * Sets the IDs of the components that should trigger a partial update.
264    *          This component will listen on the trigger components. If one of the
265    *          trigger components receives an event that will cause it to update
266    *          in some way, this component will request to be updated too.
267    * 
268    * @param partialTriggers  the new partialTriggers value
269    */
270   final public void setPartialTriggers(String[] partialTriggers)
271   {
272     setProperty(PARTIAL_TRIGGERS_KEY, (partialTriggers));
273   }
274 
275   /**
276    * Gets an onclick Javascript handler.
277    *
278    * @return  the new onclick value
279    */
280   final public String getOnclick()
281   {
282     return ComponentUtils.resolveString(getProperty(ONCLICK_KEY));
283   }
284 
285   /**
286    * Sets an onclick Javascript handler.
287    * 
288    * @param onclick  the new onclick value
289    */
290   final public void setOnclick(String onclick)
291   {
292     setProperty(ONCLICK_KEY, (onclick));
293   }
294 
295   /**
296    * Gets an ondblclick Javascript handler.
297    *
298    * @return  the new ondblclick value
299    */
300   final public String getOndblclick()
301   {
302     return ComponentUtils.resolveString(getProperty(ONDBLCLICK_KEY));
303   }
304 
305   /**
306    * Sets an ondblclick Javascript handler.
307    * 
308    * @param ondblclick  the new ondblclick value
309    */
310   final public void setOndblclick(String ondblclick)
311   {
312     setProperty(ONDBLCLICK_KEY, (ondblclick));
313   }
314 
315   /**
316    * Gets an onmousedown Javascript handler.
317    *
318    * @return  the new onmousedown value
319    */
320   final public String getOnmousedown()
321   {
322     return ComponentUtils.resolveString(getProperty(ONMOUSEDOWN_KEY));
323   }
324 
325   /**
326    * Sets an onmousedown Javascript handler.
327    * 
328    * @param onmousedown  the new onmousedown value
329    */
330   final public void setOnmousedown(String onmousedown)
331   {
332     setProperty(ONMOUSEDOWN_KEY, (onmousedown));
333   }
334 
335   /**
336    * Gets an onmouseup Javascript handler.
337    *
338    * @return  the new onmouseup value
339    */
340   final public String getOnmouseup()
341   {
342     return ComponentUtils.resolveString(getProperty(ONMOUSEUP_KEY));
343   }
344 
345   /**
346    * Sets an onmouseup Javascript handler.
347    * 
348    * @param onmouseup  the new onmouseup value
349    */
350   final public void setOnmouseup(String onmouseup)
351   {
352     setProperty(ONMOUSEUP_KEY, (onmouseup));
353   }
354 
355   /**
356    * Gets an onmouseover Javascript handler.
357    *
358    * @return  the new onmouseover value
359    */
360   final public String getOnmouseover()
361   {
362     return ComponentUtils.resolveString(getProperty(ONMOUSEOVER_KEY));
363   }
364 
365   /**
366    * Sets an onmouseover Javascript handler.
367    * 
368    * @param onmouseover  the new onmouseover value
369    */
370   final public void setOnmouseover(String onmouseover)
371   {
372     setProperty(ONMOUSEOVER_KEY, (onmouseover));
373   }
374 
375   /**
376    * Gets an onmousemove Javascript handler.
377    *
378    * @return  the new onmousemove value
379    */
380   final public String getOnmousemove()
381   {
382     return ComponentUtils.resolveString(getProperty(ONMOUSEMOVE_KEY));
383   }
384 
385   /**
386    * Sets an onmousemove Javascript handler.
387    * 
388    * @param onmousemove  the new onmousemove value
389    */
390   final public void setOnmousemove(String onmousemove)
391   {
392     setProperty(ONMOUSEMOVE_KEY, (onmousemove));
393   }
394 
395   /**
396    * Gets an onmouseout Javascript handler.
397    *
398    * @return  the new onmouseout value
399    */
400   final public String getOnmouseout()
401   {
402     return ComponentUtils.resolveString(getProperty(ONMOUSEOUT_KEY));
403   }
404 
405   /**
406    * Sets an onmouseout Javascript handler.
407    * 
408    * @param onmouseout  the new onmouseout value
409    */
410   final public void setOnmouseout(String onmouseout)
411   {
412     setProperty(ONMOUSEOUT_KEY, (onmouseout));
413   }
414 
415   /**
416    * Gets an onkeypress Javascript handler.
417    *
418    * @return  the new onkeypress value
419    */
420   final public String getOnkeypress()
421   {
422     return ComponentUtils.resolveString(getProperty(ONKEYPRESS_KEY));
423   }
424 
425   /**
426    * Sets an onkeypress Javascript handler.
427    * 
428    * @param onkeypress  the new onkeypress value
429    */
430   final public void setOnkeypress(String onkeypress)
431   {
432     setProperty(ONKEYPRESS_KEY, (onkeypress));
433   }
434 
435   /**
436    * Gets an onkeydown Javascript handler.
437    *
438    * @return  the new onkeydown value
439    */
440   final public String getOnkeydown()
441   {
442     return ComponentUtils.resolveString(getProperty(ONKEYDOWN_KEY));
443   }
444 
445   /**
446    * Sets an onkeydown Javascript handler.
447    * 
448    * @param onkeydown  the new onkeydown value
449    */
450   final public void setOnkeydown(String onkeydown)
451   {
452     setProperty(ONKEYDOWN_KEY, (onkeydown));
453   }
454 
455   /**
456    * Gets an onkeyup Javascript handler.
457    *
458    * @return  the new onkeyup value
459    */
460   final public String getOnkeyup()
461   {
462     return ComponentUtils.resolveString(getProperty(ONKEYUP_KEY));
463   }
464 
465   /**
466    * Sets an onkeyup Javascript handler.
467    * 
468    * @param onkeyup  the new onkeyup value
469    */
470   final public void setOnkeyup(String onkeyup)
471   {
472     setProperty(ONKEYUP_KEY, (onkeyup));
473   }
474 
475   /**
476    * Gets the CSS style class of the bean.
477    *
478    * @return  the new styleClass value
479    */
480   final public String getStyleClass()
481   {
482     return ComponentUtils.resolveString(getProperty(STYLE_CLASS_KEY));
483   }
484 
485   /**
486    * Sets the CSS style class of the bean.
487    * 
488    * @param styleClass  the new styleClass value
489    */
490   final public void setStyleClass(String styleClass)
491   {
492     setProperty(STYLE_CLASS_KEY, (styleClass));
493   }
494 
495   /**
496    * Gets the inline CSS style for this element
497    *
498    * @return  the new inlineStyle value
499    */
500   final public String getInlineStyle()
501   {
502     return ComponentUtils.resolveString(getProperty(INLINE_STYLE_KEY));
503   }
504 
505   /**
506    * Sets the inline CSS style for this element
507    * 
508    * @param inlineStyle  the new inlineStyle value
509    */
510   final public void setInlineStyle(String inlineStyle)
511   {
512     setProperty(INLINE_STYLE_KEY, (inlineStyle));
513   }
514 
515   /**
516    * Gets an onload Javascript handler.
517    *
518    * @return  the new onload value
519    */
520   final public String getOnload()
521   {
522     return ComponentUtils.resolveString(getProperty(ONLOAD_KEY));
523   }
524 
525   /**
526    * Sets an onload Javascript handler.
527    * 
528    * @param onload  the new onload value
529    */
530   final public void setOnload(String onload)
531   {
532     setProperty(ONLOAD_KEY, (onload));
533   }
534 
535   /**
536    * Gets an onunload Javascript handler.
537    *
538    * @return  the new onunload value
539    */
540   final public String getOnunload()
541   {
542     return ComponentUtils.resolveString(getProperty(ONUNLOAD_KEY));
543   }
544 
545   /**
546    * Sets an onunload Javascript handler.
547    * 
548    * @param onunload  the new onunload value
549    */
550   final public void setOnunload(String onunload)
551   {
552     setProperty(ONUNLOAD_KEY, (onunload));
553   }
554 
555   /**
556    * Gets the id of the component to which you want the
557    *         focus to be when the full page renders. The accessibility-mode
558    *         must be set to "inaccessible" for this feature to be on.
559    *
560    * @return  the new initialFocusId value
561    */
562   final public String getInitialFocusId()
563   {
564     return ComponentUtils.resolveString(getProperty(INITIAL_FOCUS_ID_KEY));
565   }
566 
567   /**
568    * Sets the id of the component to which you want the
569    *         focus to be when the full page renders. The accessibility-mode
570    *         must be set to "inaccessible" for this feature to be on.
571    * 
572    * @param initialFocusId  the new initialFocusId value
573    */
574   final public void setInitialFocusId(String initialFocusId)
575   {
576     setProperty(INITIAL_FOCUS_ID_KEY, (initialFocusId));
577   }
578 
579   @Override
580   public String getDefaultEventName()
581   {
582     return "load";
583   }
584 
585   @Override
586   public Collection<String> getEventNames()
587   {
588     return _EVENT_NAMES;
589   }
590 
591   @Override
592   public Map<String, List<ClientBehavior>> getClientBehaviors()
593   {
594     return super.getClientBehaviors();
595   }
596 
597   @Override
598   public void addClientBehavior(
599     String         eventName,
600     ClientBehavior behavior)
601   {
602     super.addClientBehavior(eventName, behavior);
603   }
604 
605   @Override
606   public String getFamily()
607   {
608     return COMPONENT_FAMILY;
609   }
610 
611   @Override
612   protected FacesBean.Type getBeanType()
613   {
614     return TYPE;
615   }
616 
617   /**
618    * Construct an instance of the HtmlBody.
619    */
620   protected HtmlBody(
621     String rendererType
622     )
623   {
624     super(rendererType);
625   }
626 
627   static
628   {
629     TYPE.lockAndRegister("org.apache.myfaces.trinidad.Body","org.apache.myfaces.trinidad.Body");
630   }
631 }