myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arobinso...@apache.org
Subject svn commit: r891522 [18/28] - in /myfaces/trinidad/branches/trinidad-2.0.x: ./ trinidad-api/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/bean/util/ trinidad-api/src/main/java/org/a...
Date Thu, 17 Dec 2009 02:33:11 GMT
Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/TreeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/TreeRenderer.java?rev=891522&r1=891521&r2=891522&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/TreeRenderer.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/TreeRenderer.java Thu Dec 17 02:33:05 2009
@@ -46,6 +46,7 @@
 import org.apache.myfaces.trinidad.skin.Icon;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.table.TreeUtils;
 
+
 /**
  * Renderer for trees.
  *
@@ -57,13 +58,15 @@
     this(CoreTree.TYPE);
   }
 
-  protected TreeRenderer(FacesBean.Type type)
+  protected TreeRenderer(
+    FacesBean.Type type)
   {
     super(type);
   }
 
   @Override
-  protected void findTypeConstants(FacesBean.Type type)
+  protected void findTypeConstants(
+    FacesBean.Type type)
   {
     super.findTypeConstants(type);
     _immediateKey = type.findKey("immediate");
@@ -80,7 +83,9 @@
    */
   @SuppressWarnings("unchecked")
   @Override
-  public void decode(FacesContext context, UIComponent component)
+  public void decode(
+    FacesContext context,
+    UIComponent  component)
   {
     Map<String, String> parameters =
       context.getExternalContext().getRequestParameterMap();
@@ -112,7 +117,8 @@
     FacesContext     context,
     RenderingContext rc,
     UIComponent      component,
-    FacesBean        bean) throws IOException
+    FacesBean        bean
+    ) throws IOException
   {
     // Since Train is a naming container, we can be more
     // efficient about skipping its children
@@ -142,17 +148,19 @@
   }
 
   @Override
-  protected boolean shouldRenderId(FacesContext context,
-                                   UIComponent component)
+  protected boolean shouldRenderId(
+    FacesContext context,
+    UIComponent  component)
   {
     return true;
   }
 
-  private void _renderContent(FacesContext context,
-                              RenderingContext rc,
-                              UIXHierarchy tree,
-                              FacesBean bean)
-    throws IOException
+  private void _renderContent(
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    FacesBean        bean
+    ) throws IOException
   {
     FormData fd = rc.getFormData();
     if (fd == null)
@@ -164,8 +172,8 @@
     ResponseWriter rw = context.getResponseWriter();
     rw.startElement("div", tree);
     renderId(context, tree);
-    renderAllAttributes(context, rc, bean);
-    
+    renderAllAttributes(context, rc, tree, bean);
+
     final String id = getClientId(context, tree);
     UIComponent stamp = getFacet(tree, CoreTree.NODE_STAMP_FACET);
 
@@ -199,7 +207,7 @@
       renderScriptDeferAttribute(context, rc);
       renderScriptTypeAttribute(context, rc);
 
-      _renderTreeJS(context, rc, bean);
+      _renderTreeJS(context, rc, tree, bean);
 
       //out.writeText("_setNodes('"+name+"','"+nodesRendered+"');");
 
@@ -220,19 +228,20 @@
 
   }
 
-
   // return whether to continue with rendering
 
-  protected boolean setInitialPath(UIXHierarchy tree, FacesBean bean)
+  protected boolean setInitialPath(
+    UIXHierarchy tree,
+    FacesBean    bean)
   {
     tree.setRowKey(null);
     return true;
   }
 
-
-  private boolean _isShownSelected(UIXHierarchy tree,
-                                   Map<Object, Boolean> selectedPaths,
-                                   Object currPath)
+  private boolean _isShownSelected(
+    UIXHierarchy         tree,
+    Map<Object, Boolean> selectedPaths,
+    Object               currPath)
   {
 
     boolean selected = false;
@@ -250,7 +259,8 @@
     return false;
   }
 
-  protected Map<Object, Boolean> getSelectedPaths(Object focusPath)
+  protected Map<Object, Boolean> getSelectedPaths(
+    Object focusPath)
   {
     if (focusPath == null)
       return new HashMap<Object, Boolean>(0);
@@ -261,7 +271,8 @@
     return selectedPaths;
   }
 
-  protected RowKeySet getExpandedRowKeys(UIXHierarchy tree)
+  protected RowKeySet getExpandedRowKeys(
+    UIXHierarchy tree)
   {
     return ((UIXTree) tree).getDisclosedRowKeys();
   }
@@ -271,7 +282,8 @@
    * @param rc the RenderingContext
    * @return the value of the AF_TREE_SHOW_LINES skin property
    */
-  protected boolean isShowLines( RenderingContext rc)
+  protected boolean isShowLines(
+    RenderingContext rc)
   {
     Object showLines = rc.getSkin().getProperty(SkinProperties.AF_TREE_SHOW_LINES);
     return showLines == null || showLines.equals(Boolean.TRUE);
@@ -287,11 +299,10 @@
    * @return the URI of the icon
    */
   protected String getConnectingBackgroundIcon(
-      FacesContext context,
-      RenderingContext rc,
-      boolean isLine,
-      boolean leftToRight
-  )
+    FacesContext     context,
+    RenderingContext rc,
+    boolean          isLine,
+    boolean          leftToRight)
   {
     if (!isLine || !isShowLines(rc))
       return null;
@@ -309,11 +320,10 @@
    * @return the URI of the icon
    */
   protected String getIconBackgroundIcon(
-      FacesContext context,
-      RenderingContext rc,
-      boolean isLastSibling,
-      boolean isLeftToRight
-  )
+    FacesContext     context,
+    RenderingContext rc,
+    boolean          isLastSibling,
+    boolean          isLeftToRight)
   {
     Object showLines = rc.getSkin().getProperty(SkinProperties.AF_TREE_SHOW_LINES);
     if (!isShowLines(rc))
@@ -327,16 +337,14 @@
   // render the correct icon for a specific node
 
   protected void renderExpandCell(
-      FacesContext context,
-      RenderingContext rc,
-      UIXHierarchy tree,
-      int expanded,
-      boolean isLastSibling,
-      String onclick
-  )
-      throws IOException
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    int              expanded,
+    boolean          isLastSibling,
+    String           onclick
+    ) throws IOException
   {
-
     Icon icon = null;
     String iconURI = null;
 
@@ -350,8 +358,8 @@
     Object altText = null;
 
     String text = null;
-    
-    boolean isMacOS = 
+
+    boolean isMacOS =
                Agent.PLATFORM_MACOS.equals(rc.getAgent().getPlatformName());
     // add in the expandability
     switch (expanded)
@@ -434,18 +442,19 @@
       _renderTextCell(context, rc, tree, expanded, text, altText, _ICON_WIDTH, onclick,
                       SkinSelectors.TREE_DISCLOSED_SYMBOL_STYLE_CLASS);
     }
-
   }
 
-
-  private void _renderTextCell(FacesContext context,
-                               RenderingContext rc,
-                               UIXHierarchy tree,
-                               int expanded,
-                               String text,
-                               Object altText, String width,
-                               String onclick, String styleClass)
-    throws IOException
+  private void _renderTextCell(
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    int              expanded,
+    String           text,
+    Object           altText,
+    String           width,
+    String           onclick,
+    String           styleClass
+    ) throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
 
@@ -465,17 +474,17 @@
       }
       else
       {
-        // For Non-JavaScript browsers, render an input element(type= submit) to 
-        // submit the page. Encode the name attribute with the parameter name 
-        // and value thus it would enable the browsers to include the name of 
+        // For Non-JavaScript browsers, render an input element(type= submit) to
+        // submit the page. Encode the name attribute with the parameter name
+        // and value thus it would enable the browsers to include the name of
         // this element in its payLoad if it submits the page.
         String nameAttr = TreeUtils.renderEncodedNameAttri(
                                         context,
-                                        rc, 
+                                        rc,
                                         tree,
                                         getClientId(context, tree),
                                         expanded == EXPAND_CLOSED);
-                
+
         writer.startElement("input", null);
         writer.writeAttribute("type", "submit",null);
         writer.writeAttribute("name", nameAttr, null);
@@ -502,18 +511,17 @@
   }
 
   protected void renderExpandIconCell(
-      FacesContext context,
-      RenderingContext rc,
-      String backgroundIcon,
-      String nodeBackgroundIcon,
-      String icon,
-      boolean isIconAbsoluteURI,
-      Object altText,
-      String width,
-      String height,
-      String onclick
-  )
-      throws IOException
+    FacesContext     context,
+    RenderingContext rc,
+    String           backgroundIcon,
+    String           nodeBackgroundIcon,
+    String           icon,
+    boolean          isIconAbsoluteURI,
+    Object           altText,
+    String           width,
+    String           height,
+    String           onclick
+    ) throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
 
@@ -562,12 +570,18 @@
   }
 
 
-  protected void renderIconCell(FacesContext context, RenderingContext rc,
-                                UIXHierarchy tree, String backgroundIcon,
-                                String icon, boolean isIconAbsoluteURI,
-                                Object altText, String width,
-                                String height, String onclick)
-    throws IOException
+  protected void renderIconCell(
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    String           backgroundIcon,
+    String           icon,
+    boolean          isIconAbsoluteURI,
+    Object           altText,
+    String           width,
+    String           height,
+    String           onclick
+    ) throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
 
@@ -603,21 +617,25 @@
   }
 
 
-  private static String _createFocusNodeGetter(String focusNodeId) 
+  private static String _createFocusNodeGetter(
+    String focusNodeId)
   {
     return (focusNodeId != null) ? "document.getElementById('" + focusNodeId + "')" : null;
   }
 
-  private static String _callJSSelect(UIXHierarchy tree, String jsVarName)
+  private static String _callJSSelect(
+    UIXHierarchy tree,
+    String       jsVarName)
   {
     String currencyStr = tree.getClientRowKey();
     return jsVarName + ".select(this,'" + currencyStr + "');";
   }
 
-  private String _createNewJSSelectionState(String formName,
-                                                   String treeClientId,
-                                                   String selectParam,
-                                                   String focusNodeId)
+  private String _createNewJSSelectionState(
+    String formName,
+    String treeClientId,
+    String selectParam,
+    String focusNodeId)
   {
     String treeState = TreeUtils.createNewJSCollectionComponentState(formName, treeClientId);
     String focusNode = _createFocusNodeGetter(focusNodeId);
@@ -633,10 +651,12 @@
     return jsSelectionState;
   }
 
-  private void _renderTreeJS(FacesContext context,
-                             RenderingContext rc,
-                             FacesBean bean)
-    throws IOException
+  private void _renderTreeJS(
+    FacesContext     context,
+    RenderingContext rc,
+    UIComponent      component,
+    FacesBean        bean
+    ) throws IOException
   {
     if (!rc.getProperties().containsKey(_JS_RENDERED_KEY))
     {
@@ -645,7 +665,7 @@
       writer.writeText("function _adfTreeSelector(selectParam,tState,focusNode) {" +
                        "this._selectParam = selectParam;" +
                        "this.treeState = tState;" +
-                       "this._pTag = focusNode;" + 
+                       "this._pTag = focusNode;" +
                        "}" +
                        "_adfTreeSelector.prototype.select = function(tag,path) {" +
                        "if (this._pTag != null) {" +
@@ -716,7 +736,7 @@
       //         "}",
       //         null);
 
-      boolean immediate = getImmediate(bean);
+      boolean immediate = getImmediate(component, bean);
       String buff =
         TreeUtils.setupJSTreeCollectionComponent(!immediate) + ";";
       writer.writeText(buff, null);
@@ -725,18 +745,21 @@
 
   // render one row of the tree
 
-  private void _renderNode(FacesContext context,
-                           RenderingContext rc,
-                           UIXHierarchy tree,
-                           FacesBean bean,
-                           UIComponent stamp,
-                           final String varName,
-                           RowKeySet state,
-                           Map<Object, Boolean> selectedPaths,
-                           Boolean[] prepend, boolean leftToRight,
-                           boolean isFirstSibling, boolean isLastSibling,
-                           int nodeDepth)
-    throws IOException
+  private void _renderNode(
+    FacesContext         context,
+    RenderingContext     rc,
+    UIXHierarchy         tree,
+    FacesBean            bean,
+    UIComponent          stamp,
+    final String         varName,
+    RowKeySet            state,
+    Map<Object, Boolean> selectedPaths,
+    Boolean[]            prepend,
+    boolean              leftToRight,
+    boolean              isFirstSibling,
+    boolean              isLastSibling,
+    int                  nodeDepth
+    ) throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
 
@@ -819,11 +842,11 @@
   }
 
   protected void renderNodeIconCell(
-      FacesContext context,
-      RenderingContext rc,
-      UIXHierarchy tree,
-      int expand
-  ) throws IOException
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    int              expand
+    ) throws IOException
   {
     String nodeType = getNodeType(tree);
     Icon nodeIcon = getNodeIcon(rc, nodeType, expand);
@@ -846,8 +869,7 @@
   }
 
   protected String getNodeType(
-      UIXHierarchy tree
-  )
+    UIXHierarchy tree)
   {
     String nodeType = null;
     Object rowData = tree.getRowData();
@@ -862,22 +884,15 @@
         nodeType = (String) method.invoke(rowData);
       }
     }
-    catch (IllegalAccessException e)
-    {
-    }
-    catch (NoSuchMethodException e)
-    {
-    }
-    catch (InvocationTargetException e)
-    {
-    }
+    catch (IllegalAccessException e) { ; }
+    catch (NoSuchMethodException e) { ; }
+    catch (InvocationTargetException e) { ; }
     return nodeType;
   }
 
   protected String getNodeIconSelector(
-      String nodeType,
-      int expandedState
-  )
+    String nodeType,
+    int    expandedState)
   {
     switch (expandedState)
     {
@@ -892,9 +907,9 @@
   }
 
   protected Icon getNodeIcon(
-      RenderingContext rc,
-      String nodeType,
-      int expandedState
+    RenderingContext rc,
+    String           nodeType,
+    int              expandedState
   )
   {
     if (nodeType == null || nodeType.length() == 0)
@@ -916,14 +931,14 @@
 
 
   protected void renderStampCell(
-      FacesContext context,
-      RenderingContext rc,
-      UIXHierarchy tree,
-      UIComponent stamp,
-      String onClick,
-      String treeStyle,
-      int nodeDepth
-  ) throws IOException
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    UIComponent      stamp,
+    String           onClick,
+    String           treeStyle,
+    int              nodeDepth
+    ) throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
 
@@ -935,7 +950,7 @@
     writer.startElement(XhtmlConstants.SPAN_ELEMENT, null);
     writer.writeAttribute(XhtmlConstants.ID_ATTRIBUTE, getClientId(context, tree), null);
     renderStyleClass(context, rc, treeStyle);
-    
+
     if (supportsScripting(rc))
     {
       writer.writeAttribute(XhtmlConstants.ONCLICK_ATTRIBUTE, onClick, null);
@@ -949,20 +964,20 @@
   }
 
   private void _renderNodeChildren(
-      FacesContext context,
-      RenderingContext rc,
-      UIXHierarchy tree,
-      FacesBean bean,
-      UIComponent stamp,
-      final String varName,
-      RowKeySet state,
-      Map<Object, Boolean> selectedPaths,
-      Boolean[] prepend,
-      boolean leftToRight,
-      boolean isFirstSibling,
-      boolean isLastSibling,
-      int nodeDepth
-  ) throws IOException
+    FacesContext         context,
+    RenderingContext     rc,
+    UIXHierarchy         tree,
+    FacesBean            bean,
+    UIComponent          stamp,
+    final String         varName,
+    RowKeySet            state,
+    Map<Object, Boolean> selectedPaths,
+    Boolean[]            prepend,
+    boolean              leftToRight,
+    boolean              isFirstSibling,
+    boolean              isLastSibling,
+    int                  nodeDepth
+    ) throws IOException
   {
     tree.enterContainer();
     int childCount = tree.getRowCount();
@@ -994,7 +1009,9 @@
 
   // is this row childless, open, or closed?
 
-  private int _getExpandValue(UIXHierarchy tree, RowKeySet state)
+  private int _getExpandValue(
+    UIXHierarchy tree,
+    RowKeySet    state)
   {
     if (tree.isContainer())
     {
@@ -1007,13 +1024,17 @@
     return NO_CHILDREN;
   }
 
-
   // render an icon with our own special formatting
 
-  private void _renderIcon(FacesContext context, RenderingContext rc, String icon,
-                           boolean isIconAbsoluteURI, Object text,
-                           String width, String height)
-    throws IOException
+  private void _renderIcon(
+    FacesContext     context,
+    RenderingContext rc,
+    String           icon,
+    boolean          isIconAbsoluteURI,
+    Object           text,
+    String           width,
+    String           height
+    ) throws IOException
   {
     if (icon != null)
     {
@@ -1048,7 +1069,9 @@
   // add a boolean flag to the chain of icons.
   // the chain is rendered before each icon
 
-  private Boolean[] _appendIcon(Boolean[] prepend, Boolean isLine)
+  private Boolean[] _appendIcon(
+    Boolean[] prepend,
+    Boolean   isLine)
   {
     int currLength = prepend.length;
 
@@ -1074,17 +1097,19 @@
   }
 
 
-  private void _prependIcons(FacesContext context, RenderingContext rc,
-                             UIXHierarchy tree, Boolean[] prepend,
-                             boolean leftToRight)
-    throws IOException
+  private void _prependIcons(
+    FacesContext     context,
+    RenderingContext rc,
+    UIXHierarchy     tree,
+    Boolean[]        prepend,
+    boolean          leftToRight
+    ) throws IOException
   {
     int currLength = prepend.length;
     Boolean isLine;
 
     for (int i = 0; i < currLength; i++)
     {
-
       isLine = prepend[i];
 
       if (isLine != null)
@@ -1099,11 +1124,11 @@
                        _ICON_WIDTH, "100%", null);
       }
     }
-
   }
 
-
-  protected boolean getImmediate(FacesBean bean)
+  protected boolean getImmediate(
+    UIComponent component,
+    FacesBean   bean)
   {
     Object o = bean.getProperty(_immediateKey);
     if (o == null)
@@ -1112,19 +1137,17 @@
     return Boolean.TRUE.equals(o);
   }
 
-
-
   protected String getDefaultIconName()
   {
     return null;
   }
 
-
-  private void _renderStampBasedOnAccessibilty(FacesContext context,
-                                               RenderingContext rc,
-                                               UIComponent stamp,
-                                               int depth)
-    throws IOException
+  private void _renderStampBasedOnAccessibilty(
+    FacesContext     context,
+    RenderingContext rc,
+    UIComponent      stamp,
+    int              depth
+    ) throws IOException
   {
     if (isScreenReaderMode(rc))
     {
@@ -1155,7 +1178,6 @@
   private static final String _ICON_HEIGHT = "18";
   private static final String _NODE_SPACER = "3";
 
-
   // expanded states
   protected static final int NO_CHILDREN = 0;
   protected static final int EXPAND_CLOSED = 1;
@@ -1173,7 +1195,6 @@
   // Key used by StyledTextBean to query style class
   static final String _STYLE_CLASS_KEY = "_styleClass";
 
-
   private PropertyKey _immediateKey;
 
   // translation keys

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ValueRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ValueRenderer.java?rev=891522&r1=891521&r2=891522&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ValueRenderer.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/ValueRenderer.java Thu Dec 17 02:33:05 2009
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -26,18 +26,20 @@
 
 import org.apache.myfaces.trinidad.bean.FacesBean;
 import org.apache.myfaces.trinidad.bean.PropertyKey;
-
 import org.apache.myfaces.trinidadinternal.convert.ConverterUtils;
 
+
 abstract public class ValueRenderer extends XhtmlRenderer
 {
-  protected ValueRenderer(FacesBean.Type type)
+  protected ValueRenderer(
+    FacesBean.Type type)
   {
     super(type);
   }
 
   @Override
-  protected void findTypeConstants(FacesBean.Type type)
+  protected void findTypeConstants(
+    FacesBean.Type type)
   {
     super.findTypeConstants(type);
     _converterKey = type.findKey("converter");
@@ -49,14 +51,14 @@
     UIComponent  component,
     FacesBean    bean)
   {
-    Object value = getValue(bean);
-    Converter converter = getConverter(bean);
+    Object value = getValue(component, bean);
+    Converter converter = getConverter(component, bean);
     // If there's no explicitly set converter, and the value is non-null
     // and not a String, try to get a default converter
     if ((converter == null) &&
         (value != null) &&
         !(value instanceof String))
-      converter = getDefaultConverter(context, bean);
+      converter = getDefaultConverter(context, component, bean);
 
     if (converter != null)
     {
@@ -66,12 +68,12 @@
     return toString(value);
   }
 
-
   protected Converter getDefaultConverter(
     FacesContext context,
+    UIComponent  component,
     FacesBean    bean)
   {
-    ValueExpression expression = getValueExpression(bean);
+    ValueExpression expression = getValueExpression(component, bean);
     if (expression == null)
       return null;
 
@@ -79,7 +81,9 @@
     return ConverterUtils.createConverter(context, type);
   }
 
-  protected Object getValue(FacesBean bean)
+  protected Object getValue(
+    UIComponent component,
+    FacesBean   bean)
   {
     return bean.getProperty(_valueKey);
   }
@@ -87,12 +91,16 @@
   /**
    * Returns the ValueExpression for the "value" property.
    */
-  protected ValueExpression getValueExpression(FacesBean bean)
+  protected ValueExpression getValueExpression(
+    UIComponent component,
+    FacesBean   bean)
   {
     return bean.getValueExpression(_valueKey);
   }
 
-  protected Converter getConverter(FacesBean bean)
+  protected Converter getConverter(
+    UIComponent component,
+    FacesBean   bean)
   {
     return (Converter) bean.getProperty(_converterKey);
   }

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java?rev=891522&r1=891521&r2=891522&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlRenderer.java Thu Dec 17 02:33:05 2009
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -27,24 +27,25 @@
 import javax.faces.context.ResponseWriter;
 import javax.faces.render.Renderer;
 
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
 import org.apache.myfaces.trinidad.bean.FacesBean;
 import org.apache.myfaces.trinidad.bean.PropertyKey;
+import org.apache.myfaces.trinidad.component.UIXCommand;
+import org.apache.myfaces.trinidad.context.PartialPageContext;
+import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.render.CoreRenderer;
 import org.apache.myfaces.trinidad.render.TypedRenderer;
-
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
-import org.apache.myfaces.trinidad.context.PartialPageContext;
-import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidadinternal.util.FormattedTextParser;
 import org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl;
 
+
 /**
  *  @todo Move "supportsStyleAttributes()", etc., architecture
  */
-public class XhtmlRenderer extends CoreRenderer
-                           implements TypedRenderer, Cloneable
+public class XhtmlRenderer
+  extends CoreRenderer
+  implements TypedRenderer, Cloneable
 {
   public static final String TRANSPARENT_GIF = "t.gif";
 
@@ -95,39 +96,36 @@
    * <p>
    * See section 5.16 of xhtml modularization
    */
-  static public boolean supportsScripting(RenderingContext arc)
+  static public boolean supportsScripting(RenderingContext rc)
   {
-    Object scriptingSpeed = arc.getAgent().getCapabilities().get(
-            TrinidadAgent.CAP_SCRIPTING_SPEED);
+    Object scriptingSpeed =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_SCRIPTING_SPEED);
 
     return ((scriptingSpeed != null) &&
-            (TrinidadAgent.SCRIPTING_SPEED_CAP_NONE != scriptingSpeed));
+      (TrinidadAgent.SCRIPTING_SPEED_CAP_NONE != scriptingSpeed));
   }
 
-
-  static public boolean supportsEditing(RenderingContext arc)
+  static public boolean supportsEditing(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_EDITING);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_EDITING);
     return !Boolean.FALSE.equals(cap);
   }
 
-  public static boolean supportsAdvancedForms(
-    RenderingContext arc)
+  public static boolean supportsAdvancedForms(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_ADVANCED_FORMS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_ADVANCED_FORMS);
     return !Boolean.FALSE.equals(cap);
   }
 
   /**
    * See section 5.14 of xhtml modularization.
    */
-  public static boolean supportsIntrinsicEvents(
-    RenderingContext arc)
+  public static boolean supportsIntrinsicEvents(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_INTRINSIC_EVENTS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_INTRINSIC_EVENTS);
     return !Boolean.FALSE.equals(cap);
   }
 
@@ -139,18 +137,16 @@
    * <p>
    * See section 5.18 of xhtml modularization
    */
-  public static boolean supportsStyleAttributes(
-          RenderingContext arc
-          )
+  public static boolean supportsStyleAttributes(RenderingContext rc)
   {
-    return (arc.getAgent().getCapabilities().get(TrinidadAgent.CAP_STYLE_ATTRIBUTES) !=
-            TrinidadAgent.STYLES_NONE);
+    return (rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_STYLE_ATTRIBUTES) !=
+      TrinidadAgent.STYLES_NONE);
   }
 
-  static public boolean supportsNavigation(RenderingContext arc)
+  static public boolean supportsNavigation(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_NAVIGATION);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_NAVIGATION);
     return !Boolean.FALSE.equals(cap);
   }
 
@@ -159,55 +155,52 @@
    * <p>
    * See section 5.4.1 of xhtml modularization.
    */
-  public static boolean supportsTextPresentation(
-          RenderingContext arc
-          )
+  public static boolean supportsTextPresentation(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_TEXT_PRESENTATION);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_TEXT_PRESENTATION);
     return !Boolean.FALSE.equals(cap);
   }
-  static public boolean supportsAccessKeys(RenderingContext arc)
+
+  static public boolean supportsAccessKeys(RenderingContext rc)
   {
     // In screen reader mode, disable access keys.  Despite
     // the name, they are currently considered an accessibility
     // liability
-    if (isScreenReaderMode(arc))
+    if (isScreenReaderMode(rc))
       return false;
 
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_ACCESS_KEYS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_ACCESS_KEYS);
     return !Boolean.FALSE.equals(cap);
   }
 
-  static public final boolean supportsDisabledFormElements(RenderingContext arc)
+  static public final boolean supportsDisabledFormElements(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_DISABLED_FORM_ELEMENTS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_DISABLED_FORM_ELEMENTS);
     return !Boolean.FALSE.equals(cap);
 
   }
 
-  static public final boolean supportsReadonlyFormElements(RenderingContext arc)
+  static public final boolean supportsReadonlyFormElements(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_READONLY_FORM_ELEMENTS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_READONLY_FORM_ELEMENTS);
     return !Boolean.FALSE.equals(cap);
 
   }
 
-  static public final boolean supportsAutoCompleteFormElements(
-     RenderingContext arc)
+  static public final boolean supportsAutoCompleteFormElements(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_AUTO_COMPLETE_FORM_ELEMENTS);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_AUTO_COMPLETE_FORM_ELEMENTS);
     return !Boolean.FALSE.equals(cap);
   }
 
-  static public final boolean supportsSeparateWindow(
-    RenderingContext arc)
+  static public final boolean supportsSeparateWindow(RenderingContext rc)
   {
-    return XhtmlUtils.supportsSeparateWindow(arc.getAgent());
+    return XhtmlUtils.supportsSeparateWindow(rc.getAgent());
   }
 
   /**
@@ -216,12 +209,10 @@
    * <p>
    * See section 5.12 of xhtml modularization.
    */
-  static public final boolean supportsTarget(
-     RenderingContext arc)
-
+  static public final boolean supportsTarget(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                    TrinidadAgent.CAP_TARGET);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_TARGET);
     return !Boolean.FALSE.equals(cap);
   }
 
@@ -230,20 +221,17 @@
    * @param context a <code>RenderingContext</code>
    * @return a <code>boolean</code>
    */
-    
-  public static boolean supportsNarrowScreen(RenderingContext arc)
+  public static boolean supportsNarrowScreen(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get( 
-                                 TrinidadAgent.CAP_NARROW_SCREEN);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_NARROW_SCREEN);
     return Boolean.TRUE.equals(cap);
   }
 
-
   //
   // END OF AGENT CAPABILITY CONVENIENCE METHODS
   //
 
-
   @Override
   protected boolean skipDecode(FacesContext context)
   {
@@ -264,7 +252,6 @@
     return TrinidadFilterImpl.isExecutingDialogReturn(context);
   }
 
-
   /**
    * Returns true if the component can skip its own rendering;
    * true if PPR is on for this request, is not currently active,
@@ -274,14 +261,11 @@
    * <p>
    * Call this overload if you have the clientId already.
    */
-  protected boolean canSkipRendering(
-    RenderingContext rc,
-    String           clientId)
+  protected boolean canSkipRendering(RenderingContext rc, String clientId)
   {
     PartialPageContext ppc = rc.getPartialPageContext();
-    if ((ppc == null) ||
-        ppc.isInsidePartialTarget() ||
-        ppc.isPartialTarget(clientId))
+    if ((ppc == null) || ppc.isInsidePartialTarget() ||
+      ppc.isPartialTarget(clientId))
       return false;
 
     return true;
@@ -296,14 +280,11 @@
    * <p>
    * Call this overload if you don't have the clientId already.
    */
-  protected boolean canSkipRendering(
-    FacesContext     context,
-    RenderingContext rc,
-    UIComponent      component)
+  protected boolean canSkipRendering(FacesContext context,
+    RenderingContext rc, UIComponent component)
   {
     PartialPageContext ppc = rc.getPartialPageContext();
-    if ((ppc == null) ||
-        ppc.isInsidePartialTarget())
+    if ((ppc == null) || ppc.isInsidePartialTarget())
       return false;
 
     String clientId = component.getClientId(context);
@@ -319,12 +300,11 @@
    * @todo Profile and possibly optimize.
    */
   @Override
-  protected boolean shouldRenderId(
-    FacesContext context,
-    UIComponent  component)
+  protected boolean shouldRenderId(FacesContext context,
+    UIComponent component)
   {
     // If there's partial triggers, always render an ID if possible
-    if (getPartialTriggers(getFacesBean(component)) != null)
+    if (getPartialTriggers(component, getFacesBean(component)) != null)
     {
       return true;
     }
@@ -338,12 +318,11 @@
    * @todo Since this is non-final, it can become difficult to
    * re-divide its functionality in a subclass.  Make it final???
    */
-  protected void renderAllAttributes(
-    FacesContext        context,
-    RenderingContext arc,
-    FacesBean           bean) throws IOException
+  protected void renderAllAttributes(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean)
+    throws IOException
   {
-    renderAllAttributes(context, arc, bean, true);
+    renderAllAttributes(context, rc, component, bean, true);
   }
 
 
@@ -352,34 +331,32 @@
    * and all the Javascript attributes. Takes a boolean to determine if
    * renderStyleAttributes should be called, which renders "class", "style"
    */
-  protected void renderAllAttributes(
-    FacesContext        context,
-    RenderingContext arc,
-    FacesBean           bean,
-    boolean             renderStyleAttrs) throws IOException
+  protected void renderAllAttributes(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean,
+    boolean renderStyleAttrs)
+    throws IOException
   {
-    renderShortDescAttribute(context, arc, bean);
+    renderShortDescAttribute(context, rc, component, bean);
     // render the events only if the browser supports JavaScript
-    if (supportsScripting(arc))
+    if (supportsScripting(rc))
     {
-      renderEventHandlers(context, bean);
+      renderEventHandlers(context, component, bean);
     }
     if (renderStyleAttrs)
-      renderStyleAttributes(context, arc, bean);
+      renderStyleAttributes(context, rc, component, bean);
 
   }
+
   /**
    * Renders the inline style attribute for the specified node
    */
-  public static void renderInlineStyleAttribute(
-    FacesContext        context,
-    RenderingContext arc,
-    String              style
-    ) throws IOException
+  public static void renderInlineStyleAttribute(FacesContext context,
+    RenderingContext rc, UIComponent component, String style)
+    throws IOException
   {
     if (style != null)
     {
-      if (supportsStyleAttributes(arc))
+      if (supportsStyleAttributes(rc))
       {
         ResponseWriter writer = context.getResponseWriter();
         writer.writeAttribute("style", style, null);
@@ -388,41 +365,38 @@
     }
   }
 
-  protected void renderInlineStyle(
-    FacesContext        context,
-    RenderingContext arc,
-    FacesBean           bean) throws IOException
+  protected void renderInlineStyle(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean)
+    throws IOException
   {
-    String style = getInlineStyle(bean);
+    String style = getInlineStyle(component, bean);
     if (style != null)
     {
-      context.getResponseWriter().writeAttribute("style",
-                                                 style,
-                                                 "inlineStyle");
+      context.getResponseWriter().writeAttribute("style", style,
+          "inlineStyle");
     }
   }
 
-  protected void renderShortDescAttribute(
-    FacesContext        context,
-    RenderingContext arc,
-    FacesBean           bean) throws IOException
+  protected void renderShortDescAttribute(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean)
+    throws IOException
   {
-    String shortDesc = getShortDesc(bean);
+    String shortDesc = getShortDesc(component, bean);
     if (shortDesc != null)
-      context.getResponseWriter().writeAttribute("title",
-                                                 shortDesc,
-                                                 "shortDesc");
+      context.getResponseWriter().writeAttribute("title", shortDesc,
+          "shortDesc");
   }
 
-  protected void renderStyleAttributes(
-    FacesContext        context,
-    RenderingContext arc,
-    FacesBean           bean) throws IOException
+  protected void renderStyleAttributes(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean)
+    throws IOException
   {
-    renderStyleAttributes(context, arc, bean, getDefaultStyleClass(bean));
+    renderStyleAttributes(context, rc, component, bean,
+        getDefaultStyleClass(component, bean));
   }
 
-  protected String getDefaultStyleClass(FacesBean bean)
+  protected String getDefaultStyleClass(UIComponent component,
+    FacesBean bean)
   {
     return null;
   }
@@ -430,24 +404,25 @@
   /**
    * When there's a default style class pass it in to this method
    */
-  protected void renderStyleAttributes(
-    FacesContext        context,
-    RenderingContext    arc,
-    FacesBean           bean,
-    String              defaultStyleClass) throws IOException
-  {
-    String styleClass = getStyleClass(bean);
-    List<String> parsedStyleClasses = OutputUtils.parseStyleClassList(styleClass);
+  protected void renderStyleAttributes(FacesContext context,
+    RenderingContext rc, UIComponent component, FacesBean bean,
+    String defaultStyleClass)
+    throws IOException
+  {
+    String styleClass = getStyleClass(component, bean);
+    List<String> parsedStyleClasses =
+      OutputUtils.parseStyleClassList(styleClass);
 
     if (defaultStyleClass != null)
     {
-      if(styleClass!= null )
+      if (styleClass != null)
       {
         // If we've got both a defaultStyleClass and a styleClass,
         // build up an array containing each - and if the styleClass
         // is really a list of styleClasses, break it apart so it
         // can be compressed correctly
-        int styleCount = (parsedStyleClasses == null) ? 1 : parsedStyleClasses.size();
+        int styleCount =
+          (parsedStyleClasses == null)? 1: parsedStyleClasses.size();
         String[] styleClasses = new String[1 + styleCount];
         if (parsedStyleClasses != null)
         {
@@ -461,84 +436,79 @@
 
         styleClasses[styleCount] = defaultStyleClass;
 
-        renderStyleClasses(context,
-                           arc,
-                           styleClasses);
+        renderStyleClasses(context, rc, styleClasses);
       }
       else
       {
-        renderStyleClass(context, arc, defaultStyleClass);
+        renderStyleClass(context, rc, defaultStyleClass);
       }
     }
     else if (styleClass != null)
     {
       if (parsedStyleClasses == null)
       {
-        styleClass = arc.getStyleClass(styleClass);
+        styleClass = rc.getStyleClass(styleClass);
         context.getResponseWriter().writeAttribute("class",
-                                                   arc.getStyleClass(styleClass),
-                                                   "styleClass");
+            rc.getStyleClass(styleClass), "styleClass");
       }
       else
       {
-        renderStyleClasses(context,
-                           arc,
-                           parsedStyleClasses.toArray(
-                                   new String[parsedStyleClasses.size()]));
+        renderStyleClasses(context, rc,
+            parsedStyleClasses.toArray(new String[parsedStyleClasses.size()]));
       }
     }
 
-    String style = getInlineStyle(bean);
+    String style = getInlineStyle(component, bean);
     if (style != null)
     {
-      context.getResponseWriter().writeAttribute("style",
-                                                 style,
-                                                 "inlineStyle");
+      context.getResponseWriter().writeAttribute("style", style,
+          "inlineStyle");
     }
   }
 
-
   /**
    * Render all the Javascript attributes.
    */
-  protected void renderEventHandlers(
-    FacesContext context,
-    FacesBean    bean) throws IOException
+  protected void renderEventHandlers(FacesContext context,
+    UIComponent component, FacesBean bean)
+    throws IOException
   {
     ResponseWriter rw = context.getResponseWriter();
-    rw.writeAttribute("onclick", getOnclick(bean),  "onclick");
-    rw.writeAttribute("ondblclick", getOndblclick(bean),  "ondblclick");
-    rw.writeAttribute("onkeydown", getOnkeydown(bean),  "onkeydown");
-    rw.writeAttribute("onkeyup", getOnkeyup(bean),  "onkeyup");
-    rw.writeAttribute("onkeypress", getOnkeypress(bean),  "onkeypress");
-    rw.writeAttribute("onmousedown", getOnmousedown(bean),  "onmousedown");
-    rw.writeAttribute("onmousemove", getOnmousemove(bean),  "onmousemove");
-    rw.writeAttribute("onmouseout", getOnmouseout(bean),  "onmouseout");
-    rw.writeAttribute("onmouseover", getOnmouseover(bean),  "onmouseover");
-    rw.writeAttribute("onmouseup", getOnmouseup(bean),  "onmouseup");
-  }
-
-
-  protected static void renderHAlign(
-    FacesContext        context,
-    RenderingContext arc,
-    Object              hAlign) throws IOException
+    rw.writeAttribute("onclick", getOnclick(component, bean), "onclick");
+    rw.writeAttribute("ondblclick", getOndblclick(component, bean),
+        "ondblclick");
+    rw.writeAttribute("onkeydown", getOnkeydown(component, bean),
+        "onkeydown");
+    rw.writeAttribute("onkeyup", getOnkeyup(component, bean), "onkeyup");
+    rw.writeAttribute("onkeypress", getOnkeypress(component, bean),
+        "onkeypress");
+    rw.writeAttribute("onmousedown", getOnmousedown(component, bean),
+        "onmousedown");
+    rw.writeAttribute("onmousemove", getOnmousemove(component, bean),
+        "onmousemove");
+    rw.writeAttribute("onmouseout", getOnmouseout(component, bean),
+        "onmouseout");
+    rw.writeAttribute("onmouseover", getOnmouseover(component, bean),
+        "onmouseover");
+    rw.writeAttribute("onmouseup", getOnmouseup(component, bean),
+        "onmouseup");
+  }
+
+  protected static void renderHAlign(FacesContext context,
+    RenderingContext rc, Object hAlign)
+    throws IOException
   {
     if (hAlign != null)
     {
-      boolean rtl = arc.isRightToLeft();
+      boolean rtl = rc.isRightToLeft();
 
       if ("start".equals(hAlign))
       {
-        hAlign = (rtl)
-                  ? "right"
-                  : "left";
+        hAlign = (rtl)? "right": "left";
       }
       else if ("end".equals(hAlign))
       {
-        hAlign = (rtl)
-                  ? "left"
-                  : "right";
+        hAlign = (rtl)? "left": "right";
       }
 
       context.getResponseWriter().writeAttribute("align", hAlign, null);
@@ -549,11 +519,9 @@
   // FORMATTED TEXT
   //
 
-
-  final protected void renderPossiblyFormattedText(
-    FacesContext context,
-    Object       textValue
-    ) throws IOException
+  final protected void renderPossiblyFormattedText(FacesContext context,
+    Object textValue)
+    throws IOException
   {
     if (textValue != null)
     {
@@ -565,9 +533,9 @@
     }
   }
 
-  final protected void renderFormattedText(
-    FacesContext context,
-    Object       textValue) throws IOException
+  final protected void renderFormattedText(FacesContext context,
+    Object textValue)
+    throws IOException
   {
     if (textValue != null)
     {
@@ -594,23 +562,21 @@
   // SPACERS AND TRANSPARENT IMAGES
   //
 
-  static public String getAbsoluteImageUri(
-     FacesContext        context,
-     RenderingContext arc,
-     String              imagePath)
+  static public String getAbsoluteImageUri(FacesContext context,
+    RenderingContext rc, String imagePath)
   {
-    return getBaseImageUri(context, arc) + imagePath;
+    return getBaseImageUri(context, rc) + imagePath;
   }
 
   /**
    * @todo GET FROM REAL SOURCE?
    * @todo Cache concatentation
    */
-  static protected String getBaseImageUri(
-    FacesContext        context,
-    RenderingContext arc)
+  static protected String getBaseImageUri(FacesContext context,
+    RenderingContext rc)
   {
-    String contextUri = context.getExternalContext().getRequestContextPath();
+    String contextUri =
+      context.getExternalContext().getRequestContextPath();
     return contextUri + "/adf/images/";
   }
 
@@ -620,51 +586,36 @@
    * This method may only be called for decorative icons - icons
    * that are purely visual.
    */
-  protected final void renderDecorativeIcon(
-    FacesContext        context,
-    RenderingContext arc,
-    String              iconUri,
-    Object              width,
-    Object              height,
-    Object              id,
-    Object              altText
-    ) throws IOException
-  {
-    renderDecorativeIcon(context, arc, iconUri, width, height,
-                         id, altText, null);
-  }
-
-  protected final void renderDecorativeIcon(
-    FacesContext        context,
-    RenderingContext arc,
-    String              iconUri,
-    Object              width,
-    Object              height,
-    Object              id,
-    Object              altText,
-    UIComponent         comp
-    ) throws IOException
+  protected final void renderDecorativeIcon(FacesContext context,
+    RenderingContext rc, String iconUri, Object width, Object height,
+    Object id, Object altText)
+    throws IOException
+  {
+    renderDecorativeIcon(context, rc, iconUri, width, height, id, altText,
+        null);
+  }
+
+  protected final void renderDecorativeIcon(FacesContext context,
+    RenderingContext rc, String iconUri, Object width, Object height,
+    Object id, Object altText, UIComponent comp)
+    throws IOException
   {
     // Convert iconUri to an absolute uri
-    String absoluteUri = getAbsoluteImageUri(context, arc, iconUri);
+    String absoluteUri = getAbsoluteImageUri(context, rc, iconUri);
 
-    if ((altText == null) && !isInaccessibleMode(arc))
+    if ((altText == null) && !isInaccessibleMode(rc))
       altText = "";
 
-    OutputUtils.renderImage(context, arc, absoluteUri,
-                            width, height, id, altText, comp);
+    OutputUtils.renderImage(context, rc, absoluteUri, width, height, id,
+        altText, comp);
   }
 
-
   /**
    * Renders a vertical spacer for a specified non-null height.
    */
-  protected final void renderVerticalSpacer(
-    FacesContext        context,
-    Object              height,
-    Object              id,
-    UIComponent         comp
-    ) throws IOException
+  protected final void renderVerticalSpacer(FacesContext context,
+    Object height, Object id, UIComponent comp)
+    throws IOException
   {
     if (height != null)
     {
@@ -677,7 +628,8 @@
         //pu: CSS mandates specifying units, a crude sanity check if height
         //  does not already contain units, if yes treat it as pixels.
         boolean isUnitsNotSpecified =
-          Character.isDigit(heightString.charAt(heightString.length()-1));
+          Character.isDigit(heightString.charAt(heightString.length() -
+              1));
         if (isUnitsNotSpecified)
           heightString += "px";
         writer.writeAttribute("style", "margin-top:" + heightString, null);
@@ -689,107 +641,101 @@
   /**
    * Renders a spacer.
    */
-  protected final void renderSpacer(
-    FacesContext        context,
-    RenderingContext arc,
-    String              width,
-    String              height
-    ) throws IOException
+  protected final void renderSpacer(FacesContext context,
+    RenderingContext rc, String width, String height)
+    throws IOException
   {
-    renderTransparent(context, arc, width, height, false, null);
+    renderTransparent(context, rc, width, height, false, null);
   }
 
 
   /**
    * Renders a transparent gif using a script to save space.
    */
-  protected final void renderTransparent(
-    FacesContext        context,
-    RenderingContext arc,
-    String              width,
-    String              height,
-    boolean             needsQuoting,
-    Object              id
-    ) throws IOException
+  protected final void renderTransparent(FacesContext context,
+    RenderingContext rc, String width, String height, boolean needsQuoting,
+    Object id)
+    throws IOException
   {
     Counter counter =
-      (Counter) getRenderingProperty(arc, _SCRIPT_SPACER_COUNT);
+      (Counter) getRenderingProperty(rc, _SCRIPT_SPACER_COUNT);
     if (counter == null)
     {
       counter = new Counter();
-      setRenderingProperty(arc, _SCRIPT_SPACER_COUNT, counter);
+      setRenderingProperty(rc, _SCRIPT_SPACER_COUNT, counter);
     }
     int count = counter.count++;
 
     // do not use the script spacer, if we have already rendered an enormous
     // number of spacers. bug 3786394:
     boolean useScript =
-      ((count < 800)
-       && (TrinidadAgent.SCRIPTING_SPEED_CAP_FAST ==
-           arc.getAgent().getCapabilities().get(TrinidadAgent.CAP_SCRIPTING_SPEED)));
-    _renderTransparent(context, arc, width, height, needsQuoting, id, useScript);
+      ((count < 800) && (TrinidadAgent.SCRIPTING_SPEED_CAP_FAST ==
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_SCRIPTING_SPEED)));
+    _renderTransparent(context, rc, width, height, needsQuoting, id,
+        useScript);
   }
-  
+
   /**
-   * This method evaluates the property of the specified bean if it supports 
-   * the specified property key and if the current value is <code>null</code>, 
+   * This method evaluates the property of the specified bean if it supports
+   * the specified property key and if the current value is <code>null</code>,
    * then evaluate the default value.
    * <p>
-   * If the bean does not support the specified key, this method returns 
-   * <code>null</code>. Unsupported keys occur when the bean's type its type 
-   * returned <code>null</code> from <code>findKey</code> when 
+   * If the bean does not support the specified key, this method returns
+   * <code>null</code>. Unsupported keys occur when the bean's type its type
+   * returned <code>null</code> from <code>findKey</code> when
    * <code>findTypeConstants</code> method was called.
    * </p>
-   * 
+   *
    * @param bean the property value holder.
    * @param key  the key associated to the property to evaluate.
-   * 
-   * @return <code>null</code> if key is <code>null</code>, the current 
-   *         property value in the bean for the specified key if it was 
+   *
+   * @return <code>null</code> if key is <code>null</code>, the current
+   *         property value in the bean for the specified key if it was
    *         set, or the default value if it wasn't.
-   * 
+   *
    * @see #findTypeConstants(org.apache.myfaces.trinidad.bean.FacesBean.Type)
    */
   protected Object resolveProperty(FacesBean bean, PropertyKey key)
   {
     return resolveProperty(bean, key, true);
   }
-  
+
   /**
-   * This method evaluates the property of the specified bean if it supports 
-   * the specified property key and if the current value is <code>null</code>, 
-   * then evaluate the default value if and only if <code>checkDefault</code> 
+   * This method evaluates the property of the specified bean if it supports
+   * the specified property key and if the current value is <code>null</code>,
+   * then evaluate the default value if and only if <code>checkDefault</code>
    * is <code>true</code>.
    * <p>
-   * If the bean does not support the specified key, this method returns 
-   * <code>null</code>. Unsupported keys occur when the bean's type its type 
-   * returned <code>null</code> from <code>findKey</code> when 
+   * If the bean does not support the specified key, this method returns
+   * <code>null</code>. Unsupported keys occur when the bean's type its type
+   * returned <code>null</code> from <code>findKey</code> when
    * <code>findTypeConstants</code> method was called.
    * </p>
-   * 
+   *
    * @param bean         the property value holder.
    * @param key          the key associated to the property to evaluate.
-   * @param checkDefault a flag to tell the method to look for the default value 
+   * @param checkDefault a flag to tell the method to look for the default value
    *                     if no value was explicitely set.
-   * 
-   * @return <code>null</code> if key is <code>null</code>, the current 
-   *         property value in the bean for the specified key if it was 
-   *         set, or the default value if it wasn't and checkDefault is 
+   *
+   * @return <code>null</code> if key is <code>null</code>, the current
+   *         property value in the bean for the specified key if it was
+   *         set, or the default value if it wasn't and checkDefault is
    *         <code>true</code>.
    */
-  protected Object resolveProperty(FacesBean bean, PropertyKey key, boolean checkDefault)
+  protected Object resolveProperty(FacesBean bean, PropertyKey key,
+    boolean checkDefault)
   {
     if (key == null)
     {
       return null;
     }
-    
+
     Object value = bean.getProperty(key);
     if (value == null && checkDefault)
     {
       value = key.getDefault();
     }
-    
+
     return value;
   }
 
@@ -803,47 +749,42 @@
    * then an html IMG tag will be used.
    * @todo fixup call to addLib
    */
-  private void _renderTransparent(
-    FacesContext        context,
-    RenderingContext arc,
-    String              width,
-    String              height,
-    boolean             needsQuoting,
-    Object              id,
-    boolean             useScript
-    ) throws IOException
+  private void _renderTransparent(FacesContext context,
+    RenderingContext rc, String width, String height, boolean needsQuoting,
+    Object id, boolean useScript)
+    throws IOException
   {
-    PartialPageContext pContext = arc.getPartialPageContext();
+    PartialPageContext pContext = rc.getPartialPageContext();
 
     // cannot use t() in MarlinCore.js on a partial rendering pass
     // just render the icon.
     if (!useScript || (pContext != null))
     {
-      renderDecorativeIcon(context, arc, TRANSPARENT_GIF,
-                           width, height, id, null);
+      renderDecorativeIcon(context, rc, TRANSPARENT_GIF, width, height, id,
+          null);
     }
     else
     {
       // IE has fast javascript, so render has a js function call
       ResponseWriter writer = context.getResponseWriter();
 
-      if (getRenderingProperty(arc,
-                               _TRANSPARENT_FUNCTION_WRITTEN_KEY) == null)
+      if (getRenderingProperty(rc, _TRANSPARENT_FUNCTION_WRITTEN_KEY) ==
+        null)
       {
         // determine the transparent image's URI
-        String transparentURI = getAbsoluteImageUri(context, arc, TRANSPARENT_GIF);
+        String transparentURI =
+          getAbsoluteImageUri(context, rc, TRANSPARENT_GIF);
 
-        setRenderingProperty(arc,
-                             _TRANSPARENT_FUNCTION_WRITTEN_KEY,
-                             Boolean.TRUE);
+        setRenderingProperty(rc, _TRANSPARENT_FUNCTION_WRITTEN_KEY,
+            Boolean.TRUE);
 
         // make sure the transparent image function is loaded
-        XhtmlUtils.addLib(context, arc, "t()");
+        XhtmlUtils.addLib(context, rc, "t()");
 
         writer.startElement("script", null);
         // Bug #3426092:
         // render the type="text/javascript" attribute in accessibility mode
-        renderScriptTypeAttribute(context, arc);
+        renderScriptTypeAttribute(context, rc);
 
         writer.writeAttribute("id", id, null);
 
@@ -854,7 +795,7 @@
         // store accessibility mode as javascript variable
         // which is used in t()
         writer.write("var _axm");
-        if (!isInaccessibleMode(arc))
+        if (!isInaccessibleMode(rc))
           writer.write("=1");
         writer.write(";");
       }
@@ -863,7 +804,7 @@
         writer.startElement("script", null);
         // Bug #3426092:
         // render the type="text/javascript" attribute in accessibility mode
-        renderScriptTypeAttribute(context, arc);
+        renderScriptTypeAttribute(context, rc);
         writer.writeAttribute("id", id, null);
       }
 
@@ -918,6 +859,7 @@
   //
   // JAVASCRIPT RENDERING
   //
+
   /**
    * Renders the "defer" attribute for a script element.
    * In order to support partial page rendering, scripts must
@@ -931,9 +873,9 @@
    * Note: ResponseWriter.startElement("script", null) must be called
    * before calling this method.
    */
-  public static void renderScriptDeferAttribute(
-    FacesContext        context,
-    RenderingContext arc) throws IOException
+  public static void renderScriptDeferAttribute(FacesContext context,
+    RenderingContext rc)
+    throws IOException
   {
     // At the moment we only render the defer attribute if
     // we are in the partial rendering pass.  This is to
@@ -947,7 +889,8 @@
     // ScriptBufferingResponseWriter.  Otherwise, we run into bug
     // 2466017.
     if (false)
-      context.getResponseWriter().writeAttribute("defer", Boolean.TRUE, null);
+      context.getResponseWriter().writeAttribute("defer", Boolean.TRUE,
+          null);
   }
 
   /**
@@ -958,149 +901,189 @@
    * Note: ResponseWriter.startElement("script", null) must be called
    * before calling this method.
    */
-  public static void renderScriptTypeAttribute(
-    FacesContext        context,
-    RenderingContext arc) throws IOException
+  public static void renderScriptTypeAttribute(FacesContext context,
+    RenderingContext rc)
+    throws IOException
   {
-    if (!isInaccessibleMode(arc))
+    if (!isInaccessibleMode(rc))
     {
       context.getResponseWriter().writeAttribute("type",
-                                                 _ACCESSIBILITY_SCRIPT_TYPE,
-                                                 null);
+          _ACCESSIBILITY_SCRIPT_TYPE, null);
     }
   }
 
 
   /**
    * This method renders an input element of type "submit". The input element's
-   * name attribute is encoded with parameter name and value pairs. Thus, it 
-   * would enable Non-JavaScript browsers to include the element's name in 
-   * their payLoad, if the element submits the page.    
+   * name attribute is encoded with parameter name and value pairs. Thus, it
+   * would enable Non-JavaScript browsers to include the element's name in
+   * their payLoad, if the element submits the page.
    *
    * @param context a <code>FacesContext</code>
-   * @param arc a <code>RenderingContext</code>
+   * @param rc a <code>RenderingContext</code>
    * @param valueAttri a <code>String</code> it is the value attribute
    *  of the submit button
    * @param nameAttri  a <code>String</code> it is the name attribute
    *  of the submit button
-   * 
+   *
    */
-  public static void renderSubmitButtonNonJSBrowser(
-    FacesContext     context,
-    RenderingContext arc,
-    String           valueAttri,
-    String           nameAttri
-    ) throws IOException
+  public static void renderSubmitButtonNonJSBrowser(FacesContext context,
+    RenderingContext rc, String valueAttri, String nameAttri)
+    throws IOException
   {
     ResponseWriter writer = context.getResponseWriter();
     writer.startElement("input", null);
     writer.writeAttribute("type", "submit", null);
     writer.writeAttribute("value", valueAttri, null);
     writer.writeAttribute("name", nameAttri, null);
-    renderStyleClass(context, arc, 
-                       SkinSelectors.AF_COMMAND_BUTTON_STYLE_CLASS);
+    renderStyleClass(context, rc,
+        SkinSelectors.AF_COMMAND_BUTTON_STYLE_CLASS);
     writer.endElement("input");
   }
- 
+
   //
   // ATTRIBUTE HOOKS
   //
-  protected String getShortDesc(FacesBean bean)
+
+  protected String getShortDesc(
+    UIComponent component,
+    FacesBean   bean)
   {
     return toString(bean.getProperty(_shortDescKey));
   }
 
-  protected String getStyleClass(FacesBean bean)
+  protected String getStyleClass(
+    UIComponent component,
+    FacesBean   bean)
   {
     return toString(bean.getProperty(_styleClassKey));
   }
 
-  protected String getInlineStyle(FacesBean bean)
+  protected String getInlineStyle(
+    UIComponent component,
+    FacesBean   bean)
   {
     return toString(bean.getProperty(_inlineStyleKey));
   }
 
-  protected String getOnclick(FacesBean bean)
+  protected String getOnclick(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onclickKey == null)
       return null;
 
-    return toString(bean.getProperty(_onclickKey));
+    return XhtmlUtils.getClientEventHandler(
+      FacesContext.getCurrentInstance(),
+      component,
+      "click",
+      component instanceof UIXCommand ? "action" : null,
+      toString(bean.getProperty(_onclickKey)),
+      null);
   }
 
-  protected String getOndblclick(FacesBean bean)
+  protected String getOndblclick(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_ondblclickKey == null)
       return null;
 
-    return toString(bean.getProperty(_ondblclickKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "dblclick", null, toString(bean.getProperty(_ondblclickKey)), null);
   }
 
-  protected String getOnkeydown(FacesBean bean)
+  protected String getOnkeydown(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onkeydownKey == null)
       return null;
 
-    return toString(bean.getProperty(_onkeydownKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "keydown", null, toString(bean.getProperty(_onkeydownKey)), null);
   }
 
-  protected String getOnkeyup(FacesBean bean)
+  protected String getOnkeyup(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onkeyupKey == null)
       return null;
 
-    return toString(bean.getProperty(_onkeyupKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "keyup", null, toString(bean.getProperty(_onkeyupKey)), null);
   }
 
-  protected String getOnkeypress(FacesBean bean)
+  protected String getOnkeypress(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onkeypressKey == null)
       return null;
 
-    return toString(bean.getProperty(_onkeypressKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "keypress", null, toString(bean.getProperty(_onkeypressKey)), null);
   }
 
-  protected String getOnmousedown(FacesBean bean)
+  protected String getOnmousedown(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onmousedownKey == null)
       return null;
 
-    return toString(bean.getProperty(_onmousedownKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "mousedown", null, toString(bean.getProperty(_onmousedownKey)), null);
   }
 
-  protected String getOnmousemove(FacesBean bean)
+  protected String getOnmousemove(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onmousemoveKey == null)
       return null;
 
-    return toString(bean.getProperty(_onmousemoveKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "mousemove", null, toString(bean.getProperty(_onmousemoveKey)), null);
   }
 
-  protected String getOnmouseout(FacesBean bean)
+  protected String getOnmouseout(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onmouseoutKey == null)
       return null;
 
-    return toString(bean.getProperty(_onmouseoutKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "mouseout", null, toString(bean.getProperty(_onmouseoutKey)), null);
   }
 
-  protected String getOnmouseover(FacesBean bean)
+  protected String getOnmouseover(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onmouseoverKey == null)
       return null;
 
-    return toString(bean.getProperty(_onmouseoverKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "mouseover", null, toString(bean.getProperty(_onmouseoverKey)), null);
   }
 
-  protected String getOnmouseup(FacesBean bean)
+  protected String getOnmouseup(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_onmouseupKey == null)
       return null;
 
-    return toString(bean.getProperty(_onmouseupKey));
+    return XhtmlUtils.getClientEventHandler(FacesContext.getCurrentInstance(), component,
+             "mouseup", null, toString(bean.getProperty(_onmouseupKey)), null);
   }
 
-  protected String[] getPartialTriggers(FacesBean bean)
+  protected String[] getPartialTriggers(
+    UIComponent component,
+    FacesBean   bean)
   {
     if (_partialTriggersKey == null)
     {
@@ -1108,21 +1091,21 @@
     }
     else
     {
-      return (String[])bean.getProperty(_partialTriggersKey);
+      return (String[]) bean.getProperty(_partialTriggersKey);
     }
   }
 
   /**
-   * Returns true if the agent supports the "onclick" JS Handler in an "input" 
+   * Returns true if the agent supports the "onclick" JS Handler in an "input"
    * HTML element of type "image"
    */
-  static public boolean supportsOnClickOnImgInput(RenderingContext arc)
+  static public boolean supportsOnClickOnImgInput(RenderingContext rc)
   {
-    Object cap = arc.getAgent().getCapabilities().get(
-                      TrinidadAgent.CAP_ONCLICK_IMG_INPUT);
+    Object cap =
+      rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_ONCLICK_IMG_INPUT);
     return !Boolean.FALSE.equals(cap);
   }
-  
+
   private PropertyKey _shortDescKey;
   private PropertyKey _styleClassKey;
   private PropertyKey _inlineStyleKey;
@@ -1139,7 +1122,8 @@
   private PropertyKey _partialTriggersKey;
 
   // The value bound to the type attribute in script tags in accessibilty mode.
-  private static final String _ACCESSIBILITY_SCRIPT_TYPE = "text/javascript";
+  private static final String _ACCESSIBILITY_SCRIPT_TYPE =
+    "text/javascript";
 
   // Key to look up the number of times we have rendered the script spacer:
   private static final Object _SCRIPT_SPACER_COUNT = new Object();
@@ -1149,5 +1133,6 @@
   //                 XhtmlLafRenderer.__TRANSPARENT_URL_KEY = "_t.gif";
   private static final String _TRANSPARENT_FUNCTION_WRITTEN_KEY = "_t.gif";
 
-  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(XhtmlRenderer.class);
+  private static final TrinidadLogger _LOG =
+    TrinidadLogger.createTrinidadLogger(XhtmlRenderer.class);
 }

Modified: myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlUtils.java?rev=891522&r1=891521&r2=891522&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlUtils.java (original)
+++ myfaces/trinidad/branches/trinidad-2.0.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/XhtmlUtils.java Thu Dec 17 02:33:05 2009
@@ -20,13 +20,20 @@
 
 import java.io.IOException;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.component.behavior.ClientBehaviorHint;
+import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
@@ -37,6 +44,7 @@
 import org.apache.myfaces.trinidad.context.Agent;
 import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.render.CoreRenderer;
 import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.jsLibs.Scriptlet;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.jsLibs.XhtmlScriptletFactory;
@@ -68,7 +76,6 @@
     }
   }
 
-
   /**
    * Returns true if the agent has enough support for Trinidad
    * to launch separate windows.  We require both multiple window
@@ -105,7 +112,6 @@
     return compID.toString();
   }
 
-
   /**
    * Registers a scriptlet.
    */
@@ -117,11 +123,12 @@
   /**
    */
   static public void addLib(
-    FacesContext        context,
-    RenderingContext arc,
-    Object              libKey) throws IOException
+    FacesContext     context,
+    RenderingContext rc,
+    Object           libKey
+    ) throws IOException
   {
-    if ((XhtmlRenderer.supportsScripting(arc)) && (libKey != null))
+    if ((XhtmlRenderer.supportsScripting(rc)) && (libKey != null))
     {
       Scriptlet scriptlet = _sScriptletTable.get(libKey);
       if (scriptlet == null)
@@ -131,12 +138,11 @@
       }
       else
       {
-        scriptlet.outputScriptlet(context, arc);
+        scriptlet.outputScriptlet(context, rc);
       }
     }
   }
 
-
   /**
    * Write out a script element importing a library.
    * The given URL will only be written once to the page.
@@ -200,8 +206,7 @@
     writer.endElement("script");
   }
 
-
-   /**
+  /**
    * Return the chained JavaScript
    */
   public static String getChainedJS(
@@ -271,6 +276,74 @@
     return outBuilder.toString();
   }
 
+  /**
+   * Return the chained JavaScript
+   */
+  public static String getChainedJS(
+    boolean   shortCircuit,
+    String... scripts
+    )
+  {
+    if (scripts.length == 0)
+    {
+      return null;
+    }
+
+    if (scripts.length <= 2)
+    {
+      // Use the more efficient code for two scripts, or less
+      return getChainedJS(scripts[0], scripts.length == 2 ? scripts[1] : null, shortCircuit);
+    }
+
+    StringBuilder builder = new StringBuilder(100);
+    builder.append("return _chainMultiple([");
+    int firstNonNullScript = -1;
+    int numScripts = 0;
+
+    for (int i = 0, size = scripts.length; i < size; ++i)
+    {
+      String script = scripts[i];
+      if (script == null) { continue; }
+      script = script.trim();
+      if (script.length() == 0) { continue; }
+      ++numScripts;
+
+      if (firstNonNullScript == -1)
+      {
+        builder.append('\'');
+        firstNonNullScript = i;
+      }
+      else
+      {
+        builder.append(",'");
+      }
+      escapeJS(builder, script, true);
+      builder.append('\'');
+    }
+    if (numScripts == 0) { return null; }
+    if (numScripts == 1) { return scripts[firstNonNullScript]; }
+
+    RenderingContext rc = RenderingContext.getCurrentInstance();
+    if (rc.getAgent().getType().equals(Agent.TYPE_DESKTOP))
+    {
+      if (shortCircuit)
+        builder.append("],this,event,true);");
+      else
+        builder.append("],this,event);");
+    }
+    else
+    {
+      // Some mobile browsers do not support DOM Event object.
+      // If event is passed, the script crushes before the function gains
+      // control.
+      if (shortCircuit)
+        builder.append("],this,null,true);");
+      else
+        builder.append("],this,null);");
+    }
+
+    return builder.toString();
+  }
 
   /**
    * Handle escaping '/', and single quotes, plus escaping text inside of
@@ -285,8 +358,6 @@
     return escapeJS(inString, false /* inQuotes */);
   }
 
-
-
   /**
    * Handle escaping '/', and single quotes, plus escaping text inside of
    * quotes with just a String for input.  If a String in and a String out is
@@ -317,7 +388,6 @@
     }
   }
 
-
   /**
    * Handle escaping '/', and single quotes, plus escaping text inside of
    * quotes.
@@ -330,7 +400,6 @@
     escapeJS(outBuilder, inString, false /* inQuotes */);
   }
 
-
   /**
    * Handle escaping '/', and single quotes, plus escaping text inside of
    * quotes.
@@ -468,7 +537,6 @@
     builder.append(hexString);
   }
 
-
   private static void _escapeSingleQuotes(
     StringBuilder outBuilder,
     String       inString
@@ -526,7 +594,7 @@
     FastMessageFormat formatter = new FastMessageFormat(pattern);
     return formatter.format(parameters);
   }
-  
+
   /*
    * This method returns the encoded parameter name or paramater value
    * for the Non-JavaScript browsers
@@ -535,45 +603,209 @@
   {
     return param + XhtmlConstants.NO_JS_PARAMETER_KEY;
   }
-   
+
   /*
    * This method returns the name attribute of HTML elements for Non-JavaScript
-   * browsers. It is encoded with parameter name and value pair. 
+   * browsers. It is encoded with parameter name and value pair.
    */
   public static String getEncodedNameAttribute(String param[])
   {
     // The incoming array(param[]) must contain parameter name and value pair
     // in the order of <<name1>>, <<value1>>, <<name2>>, <<value2>>,...
-    // The encoded parameter name and value for the above would be 
+    // The encoded parameter name and value for the above would be
     // <<name1>><<encodingKey>><<value1>><<encodingKey>>
     // <<name2>><<encodingKey>><<value2>>
-            
+
     int noOfParam = param.length;
     int bufferLen = 0;
-    
-    // Calculate what would be the length of the encoded param name and  
+
+    // Calculate what would be the length of the encoded param name and
     // value pair. We need it to initialize the buffer size of StringBuilder.
     for(int i = 0; i < noOfParam; i++)
     {
       bufferLen += param[i].length();
     }
-    // If there are N parameter names and values, there would be N-1 
+    // If there are N parameter names and values, there would be N-1
     // encoding key so add its length also
     bufferLen  += (noOfParam -1) * XhtmlConstants.NO_JS_PARAMETER_KEY.length();
-   
+
     StringBuilder nameAttri = new StringBuilder(bufferLen);
-    
+
     //Encode all the parameter names and values except the last parameter value
     for(int i = 0; i < noOfParam-1; i++)
     {
       nameAttri.append(getEncodedParameter(param[i]));
     }
-    
+
     nameAttri.append(param[noOfParam-1]);
-  
+
     return(nameAttri.toString());
   }
-  
+
+  /**
+   * Build a client event handler (onfocus for example) including any associated
+   * client behaviors for the event.
+   *
+   * @param facesContext The faces context
+   * @param component The component
+   * @param eventName The event, without the "on*" prefix, to render
+   * @param secondaryEventName If applicable, the secondary event name. For command components,
+   * "click" and "action" behaviors are included together and for input components, "change" and
+   * "valueChange" are included together.
+   * @param eventHandlerScript Script to be executed after the behaviors. May be null
+   * @param userHandlerScript user event handler to be executed before the event handler script and
+   * any client behavior scripts. May be null.
+   */
+  public static String getClientEventHandler(
+    FacesContext facesContext,
+    UIComponent  component,
+    String       eventName,
+    String       secondaryEventName,
+    String       userHandlerScript,
+    String       eventHandlerScript
+    )
+  {
+    BehaviorsData data = null;
+    if (component instanceof ClientBehaviorHolder)
+    {
+      data = new BehaviorsData();
+      _getBehaviorScripts(facesContext, component, eventName, data);
+
+      if (secondaryEventName != null)
+      {
+        _getBehaviorScripts(facesContext, component, secondaryEventName, data);
+      }
+    }
+
+    boolean hasHandler = eventHandlerScript != null && eventHandlerScript.length() > 0;
+    boolean hasUserHandler = userHandlerScript != null && userHandlerScript.length() > 0;
+    String script = null;
+    boolean hasBehaviors = data != null && data.behaviorScripts != null &&
+      !data.behaviorScripts.isEmpty();
+
+    if (hasHandler && !hasBehaviors && !hasUserHandler)
+    {
+      script = eventHandlerScript;
+    }
+    else if (hasUserHandler && !hasBehaviors && !hasHandler)
+    {
+      script = userHandlerScript;
+    }
+    else if (!hasUserHandler && !hasHandler && hasBehaviors && data.behaviorScripts.size() == 1)
+    {
+      script = data.behaviorScripts.get(0);
+      if ("action".equals(secondaryEventName) && data.submitting)
+      {
+        // prevent the default click action if submitting
+        script += ";return false;";
+      }
+    }
+    else
+    {
+      // There are multiple scripts, we will need to chain the methods.
+      int numBehaviorScripts = hasBehaviors ? data.behaviorScripts.size() : 0;
+      int length = numBehaviorScripts;
+      if (hasHandler) { ++length; }
+      if (hasUserHandler) { ++length; }
+      String[] scripts = new String[length];
+      int index = 0;
+      boolean submitting = false;
+      if (hasUserHandler)
+      {
+        scripts[0] = userHandlerScript;
+        index = 1;
+      }
+
+      if (hasBehaviors)
+      {
+        System.arraycopy(data.behaviorScripts.toArray(), 0, scripts, index, numBehaviorScripts);
+        index += numBehaviorScripts;
+      }
+
+      if (hasHandler)
+      {
+        scripts[index] = eventHandlerScript;
+      }
+
+      script = getChainedJS(true, scripts);
+      if (submitting && "click".equals(eventName))
+      {
+        // prevent the default click action if submitting
+        script += ";return false;";
+      }
+    }
+
+    return script;
+  }
+
+  /**
+   * Gather the behavior scripts for a client behavior holder
+   *
+   * @param facesContext the faces context
+   * @param component the behavior holder (must implement ClientBehaviorHolder)
+   * @param eventName the event of the behaviors to get
+   * @param data the data to populate, which may have data from a previous invokation of this
+   * function
+   * @return the data collected while getting the behaviors (used for performance to avoid
+   * duplicate lookup and allow for lazy loading of the parameters)
+   */
+  private static void _getBehaviorScripts(
+    FacesContext  facesContext,
+    UIComponent   component,
+    String        eventName,
+    BehaviorsData data)
+  {
+    ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder)component;
+
+    List<ClientBehavior> behaviors = behaviorHolder.getClientBehaviors().get(eventName);
+    if (behaviors != null && !behaviors.isEmpty())
+    {
+      // if params are not null, a submitting behavior was found in a previous call to this
+      // function, so we do not need to check for submitting here
+      data.submitting = data.submitting || _hasSubmittingBehavior(behaviors);
+      if (data.params == null && data.submitting)
+      {
+        // We only need to gather the parameters if there is a submitting behavior, so do
+        // not incur the performance overhead if not needed
+        data.params = CoreRenderer.getBehaviorParameters(component);
+      }
+
+      ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext(
+        facesContext, component, eventName, component.getClientId(facesContext), data.params);
+
+      if (data.behaviorScripts == null)
+      {
+        data.behaviorScripts = new ArrayList<String>(behaviors.size());
+      }
+
+      for (ClientBehavior behavior : behaviors)
+      {
+        data.behaviorScripts.add(behavior.getScript(behaviorContext));
+      }
+    }
+  }
+
+  private static boolean _hasSubmittingBehavior(
+    Iterable<ClientBehavior> behaviors)
+  {
+    for (ClientBehavior behavior : behaviors)
+    {
+      if (behavior.getHints().contains(ClientBehaviorHint.SUBMITTING))
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private static class BehaviorsData
+  {
+    Collection<ClientBehaviorContext.Parameter> params;
+    List<String>                                behaviorScripts;
+    boolean                                     submitting;
+  }
+
+  private static final Object _CLIENT_BEHAVIORS_KEY = new Object();
 
   /** HashMap mapping names to their scriptlets */
   private static Map<Object, Scriptlet> _sScriptletTable =
@@ -599,5 +831,4 @@
   }
 
   private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(XhtmlUtils.class);
-
 }



Mime
View raw message