You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/02/02 21:00:44 UTC

svn commit: r1239799 [5/9] - in /myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared: application/ config/ context/flash/ renderkit/ renderkit/html/ renderkit/html/util/ resource/ util/ util/io/ util/xml/

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1239799&r1=1239798&r2=1239799&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Thu Feb  2 20:00:42 2012
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.RandomAccess;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.logging.Level;
@@ -83,28 +84,24 @@ public final class HtmlRendererUtils
     //private static final Log log = LogFactory.getLog(HtmlRendererUtils.class);
     private static final Logger log = Logger.getLogger(HtmlRendererUtils.class
             .getName());
-
     //private static final String[] EMPTY_STRING_ARRAY = new String[0];
     private static final String LINE_SEPARATOR = System.getProperty(
             "line.separator", "\r\n");
     private static final char TABULATOR = '\t';
-
     public static final String HIDDEN_COMMANDLINK_FIELD_NAME = "_idcl";
     public static final String HIDDEN_COMMANDLINK_FIELD_NAME_MYFACES_OLD = "_link_hidden_";
     public static final String HIDDEN_COMMANDLINK_FIELD_NAME_TRINIDAD = "source";
-
     public static final String CLEAR_HIDDEN_FIELD_FN_NAME = "clearFormHiddenParams";
     public static final String SUBMIT_FORM_FN_NAME = "oamSubmitForm";
     public static final String SUBMIT_FORM_FN_NAME_JSF2 = "myfaces.oam.submitForm";
     public static final String ALLOW_CDATA_SECTION_ON = "org.apache.myfaces.ResponseWriter.CdataSectionOn";
-
     public static final String NON_SUBMITTED_VALUE_WARNING 
             = "There should always be a submitted value for an input if it is rendered,"
             + " its form is submitted, and it was not originally rendered disabled or read-only."
             + "  You cannot submit a form after disabling an input element via javascript."
             + "  Consider setting read-only to true instead"
             + " or resetting the disabled value back to false prior to form submission.";
-    private static final String STR_EMPTY = "";
+    public static final String STR_EMPTY = "";
 
     private HtmlRendererUtils()
     {
@@ -119,8 +116,7 @@ public final class HtmlRendererUtils
      * from this method, the component's submittedValue property will be
      * set if the submitted form contained that component.
      */
-    public static void decodeUIInput(FacesContext facesContext,
-            UIComponent component)
+    public static void decodeUIInput(FacesContext facesContext, UIComponent component)
     {
         if (!(component instanceof EditableValueHolder))
         {
@@ -153,8 +149,7 @@ public final class HtmlRendererUtils
      * @param facesContext
      * @param component
      */
-    public static void decodeUISelectBoolean(FacesContext facesContext,
-            UIComponent component)
+    public static void decodeUISelectBoolean(FacesContext facesContext, UIComponent component)
     {
         if (!(component instanceof EditableValueHolder))
         {
@@ -176,13 +171,11 @@ public final class HtmlRendererUtils
                     || reqValue.equalsIgnoreCase("yes") || reqValue
                     .equalsIgnoreCase("true")))
             {
-                ((EditableValueHolder) component)
-                        .setSubmittedValue(Boolean.TRUE);
+                ((EditableValueHolder) component).setSubmittedValue(Boolean.TRUE);
             }
             else
             {
-                ((EditableValueHolder) component)
-                        .setSubmittedValue(Boolean.FALSE);
+                ((EditableValueHolder) component).setSubmittedValue(Boolean.FALSE);
             }
         }
         else
@@ -193,8 +186,7 @@ public final class HtmlRendererUtils
 
     public static boolean isDisabledOrReadOnly(UIComponent component)
     {
-        return isDisplayValueOnly(component) || isDisabled(component)
-                || isReadOnly(component);
+        return isDisplayValueOnly(component) || isDisabled(component) || isReadOnly(component);
     }
 
     public static boolean isDisabled(UIComponent component)
@@ -226,8 +218,7 @@ public final class HtmlRendererUtils
      * @param facesContext
      * @param component
      */
-    public static void decodeUISelectMany(FacesContext facesContext,
-            UIComponent component)
+    public static void decodeUISelectMany(FacesContext facesContext, UIComponent component)
     {
         if (!(component instanceof EditableValueHolder))
         {
@@ -235,8 +226,7 @@ public final class HtmlRendererUtils
                     + component.getClientId(facesContext)
                     + " is not an EditableValueHolder");
         }
-        Map paramValuesMap = facesContext.getExternalContext()
-                .getRequestParameterValuesMap();
+        Map paramValuesMap = facesContext.getExternalContext().getRequestParameterValuesMap();
         String clientId = component.getClientId(facesContext);
         if (isDisabledOrReadOnly(component))
         {
@@ -254,8 +244,7 @@ public final class HtmlRendererUtils
                and if the component is not readonly or has not been disabled.
                So in fact, there must be component value at this location, but for listboxes, comboboxes etc.
                the submitted value is not posted if no item is selected. */
-            ((EditableValueHolder) component)
-                    .setSubmittedValue(new String[] {});
+            ((EditableValueHolder) component).setSubmittedValue(new String[] {});
         }
     }
 
@@ -265,8 +254,7 @@ public final class HtmlRendererUtils
      * @param facesContext
      * @param component
      */
-    public static void decodeUISelectOne(FacesContext facesContext,
-            UIComponent component)
+    public static void decodeUISelectOne(FacesContext facesContext, UIComponent component)
     {
         if (!(component instanceof EditableValueHolder))
         {
@@ -278,14 +266,12 @@ public final class HtmlRendererUtils
         {
             return;
         }
-        Map paramMap = facesContext.getExternalContext()
-                .getRequestParameterMap();
+        Map paramMap = facesContext.getExternalContext().getRequestParameterMap();
         String clientId = component.getClientId(facesContext);
         if (paramMap.containsKey(clientId))
         {
             //request parameter found, set submitted value
-            ((EditableValueHolder) component).setSubmittedValue(paramMap
-                    .get(clientId));
+            ((EditableValueHolder) component).setSubmittedValue(paramMap.get(clientId));
         }
         else
         {
@@ -295,12 +281,9 @@ public final class HtmlRendererUtils
     }
 
     /**
-     * @param facesContext
-     * @param component
      * @since 4.0.0
      */
-    public static void decodeClientBehaviors(FacesContext facesContext,
-            UIComponent component)
+    public static void decodeClientBehaviors(FacesContext facesContext, UIComponent component)
     {
         if (component instanceof ClientBehaviorHolder)
         {
@@ -323,9 +306,20 @@ public final class HtmlRendererUtils
                         String clientId = paramMap.get("javax.faces.source");
                         if (component.getClientId().equals(clientId))
                         {
-                            for (ClientBehavior clientBehavior : clientBehaviorList)
+                            if (clientBehaviorList instanceof RandomAccess)
                             {
-                                clientBehavior.decode(facesContext, component);
+                                for (int i = 0, size = clientBehaviorList.size(); i < size; i++)
+                                {
+                                    ClientBehavior clientBehavior = clientBehaviorList.get(i);
+                                    clientBehavior.decode(facesContext, component);
+                                }
+                            } 
+                            else
+                            {
+                                for (ClientBehavior clientBehavior : clientBehaviorList)
+                                {
+                                    clientBehavior.decode(facesContext, component);
+                                }
                             }
                         }
                     }
@@ -338,32 +332,28 @@ public final class HtmlRendererUtils
             UISelectOne selectOne, boolean disabled, int size,
             Converter converter) throws IOException
     {
-        internalRenderSelect(facesContext, selectOne, disabled, size, false,
-                converter);
+        internalRenderSelect(facesContext, selectOne, disabled, size, false, converter);
     }
 
     public static void renderListbox(FacesContext facesContext,
             UISelectMany selectMany, boolean disabled, int size,
             Converter converter) throws IOException
     {
-        internalRenderSelect(facesContext, selectMany, disabled, size, true,
-                converter);
+        internalRenderSelect(facesContext, selectMany, disabled, size, true, converter);
     }
 
     public static void renderMenu(FacesContext facesContext,
             UISelectOne selectOne, boolean disabled, Converter converter)
             throws IOException
     {
-        internalRenderSelect(facesContext, selectOne, disabled, 1, false,
-                converter);
+        internalRenderSelect(facesContext, selectOne, disabled, 1, false, converter);
     }
 
     public static void renderMenu(FacesContext facesContext,
             UISelectMany selectMany, boolean disabled, Converter converter)
             throws IOException
     {
-        internalRenderSelect(facesContext, selectMany, disabled, 1, true,
-                converter);
+        internalRenderSelect(facesContext, selectMany, disabled, 1, true, converter);
     }
 
     private static void internalRenderSelect(FacesContext facesContext,
@@ -373,18 +363,14 @@ public final class HtmlRendererUtils
         ResponseWriter writer = facesContext.getResponseWriter();
         writer.startElement(HTML.SELECT_ELEM, uiComponent);
         if (uiComponent instanceof ClientBehaviorHolder
-                && JavascriptUtils.isJavascriptAllowed(facesContext
-                        .getExternalContext())
-                && !((ClientBehaviorHolder) uiComponent).getClientBehaviors()
-                        .isEmpty())
+                && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext())
+                && !((ClientBehaviorHolder) uiComponent).getClientBehaviors().isEmpty())
         {
-            writer.writeAttribute(HTML.ID_ATTR,
-                    uiComponent.getClientId(facesContext), null);
+            writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
         }
         else
         {
-            HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent,
-                    facesContext);
+            HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
         }
         writer.writeAttribute(HTML.NAME_ATTR,
                 uiComponent.getClientId(facesContext), null);
@@ -418,12 +404,9 @@ public final class HtmlRendererUtils
         {
             behaviors = ((ClientBehaviorHolder) uiComponent)
                     .getClientBehaviors();
-            renderBehaviorizedOnchangeEventHandler(facesContext, writer,
-                    uiComponent, behaviors);
-            renderBehaviorizedEventHandlers(facesContext, writer, uiComponent,
-                    behaviors);
-            renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext,
-                    writer, uiComponent, behaviors);
+            renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
+            renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
+            renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, behaviors);
             renderHTMLAttributes(
                     writer,
                     uiComponent,
@@ -456,8 +439,7 @@ public final class HtmlRendererUtils
     }
 
     public static Set getSubmittedOrSelectedValuesAsSet(boolean selectMany,
-            UIComponent uiComponent, FacesContext facesContext,
-            Converter converter)
+            UIComponent uiComponent, FacesContext facesContext, Converter converter)
     {
         Set lookupSet;
         if (selectMany)
@@ -498,8 +480,7 @@ public final class HtmlRendererUtils
             FacesContext facesContext, UIComponent uiComponent)
     {
         // invoke with considerValueType = false
-        return findUISelectManyConverterFailsafe(facesContext, uiComponent,
-                false);
+        return findUISelectManyConverterFailsafe(facesContext, uiComponent, false);
     }
 
     public static Converter findUISelectManyConverterFailsafe(
@@ -522,14 +503,12 @@ public final class HtmlRendererUtils
         return converter;
     }
 
-    public static Converter findUIOutputConverterFailSafe(
-            FacesContext facesContext, UIComponent uiComponent)
+    public static Converter findUIOutputConverterFailSafe(FacesContext facesContext, UIComponent uiComponent)
     {
         Converter converter;
         try
         {
-            converter = RendererUtils.findUIOutputConverter(facesContext,
-                    (UIOutput) uiComponent);
+            converter = RendererUtils.findUIOutputConverter(facesContext, (UIOutput) uiComponent);
         }
         catch (FacesException e)
         {
@@ -559,14 +538,12 @@ public final class HtmlRendererUtils
             List selectItemList) throws IOException
     {
         ResponseWriter writer = context.getResponseWriter();
-
         // check for the hideNoSelectionOption attribute
         boolean hideNoSelectionOption = isHideNoSelectionOption(component);
 
         for (Iterator it = selectItemList.iterator(); it.hasNext();)
         {
             SelectItem selectItem = (SelectItem) it.next();
-
             if (selectItem instanceof SelectItemGroup)
             {
                 writer.startElement(HTML.OPTGROUP_ELEM, component);
@@ -614,15 +591,13 @@ public final class HtmlRendererUtils
 
                 if (selected)
                 {
-                    writer.writeAttribute(HTML.SELECTED_ATTR,
-                            HTML.SELECTED_ATTR, null);
+                    writer.writeAttribute(HTML.SELECTED_ATTR, HTML.SELECTED_ATTR, null);
                 }
 
                 boolean disabled = selectItem.isDisabled();
                 if (disabled)
                 {
-                    writer.writeAttribute(HTML.DISABLED_ATTR,
-                            HTML.DISABLED_ATTR, null);
+                    writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
                 }
 
                 String labelClass = null;
@@ -832,8 +807,7 @@ public final class HtmlRendererUtils
         if (component.getId() != null
                 && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
         {
-            writer.writeAttribute(HTML.ID_ATTR,
-                    component.getClientId(facesContext), null);
+            writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext), null);
         }
     }
 
@@ -849,9 +823,158 @@ public final class HtmlRendererUtils
             writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
         }
     }
+    
+    /**
+     * Renders a html string type attribute. If the value retrieved from the component 
+     * property is "", the attribute is rendered.
+     * 
+     * @param writer
+     * @param component
+     * @param componentProperty
+     * @param htmlAttrName
+     * @return
+     * @throws IOException
+     */
+    public static final boolean renderHTMLStringPreserveEmptyAttribute(ResponseWriter writer,
+            UIComponent component, String componentProperty, String htmlAttrName)
+            throws IOException
+    {
+        String value = (String) component.getAttributes().get(componentProperty);
+        if (!isDefaultStringPreserveEmptyAttributeValue(value))
+        {
+            writer.writeAttribute(htmlAttrName, value, componentProperty);
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     * Renders a html string type attribute. If the value retrieved from the component 
+     * property is "", the attribute is rendered.
+     * 
+     * @param writer
+     * @param component
+     * @param componentProperty
+     * @param htmlAttrName
+     * @return
+     * @throws IOException
+     */
+    public static final boolean renderHTMLStringPreserveEmptyAttribute(ResponseWriter writer,
+            String componentProperty, String htmlAttrName, String value)
+            throws IOException
+    {
+        if (!isDefaultStringPreserveEmptyAttributeValue(value))
+        {
+            writer.writeAttribute(htmlAttrName, value, componentProperty);
+            return true;
+        }
+        return false;
+    }
 
-    public static void writeIdAndName(ResponseWriter writer,
-            UIComponent component, FacesContext facesContext)
+    /**
+     * Check if the value is the default for String type attributes that requires preserve "" as
+     * a valid value.
+     * 
+     * @param value
+     * @return
+     */
+    private static final boolean isDefaultStringPreserveEmptyAttributeValue(String value)
+    {
+        if (value == null)
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    /**
+     * Renders a html string type attribute. If the value retrieved from the component 
+     * property is "" or null, the attribute is not rendered.
+     * 
+     * @param writer
+     * @param component
+     * @param componentProperty
+     * @param htmlAttrName
+     * @return
+     * @throws IOException
+     */
+    public static final boolean renderHTMLStringAttribute(ResponseWriter writer,
+            UIComponent component, String componentProperty, String htmlAttrName)
+            throws IOException
+    {
+        String value = (String) component.getAttributes().get(componentProperty);
+        if (!isDefaultStringAttributeValue(value))
+        {
+            writer.writeAttribute(htmlAttrName, value, componentProperty);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Renders a html string type attribute. If the value retrieved from the component 
+     * property is "" or null, the attribute is not rendered.
+     * 
+     * @param writer
+     * @param componentProperty
+     * @param htmlAttrName
+     * @param value
+     * @return
+     * @throws IOException
+     */
+    public static final boolean renderHTMLStringAttribute(ResponseWriter writer,
+            String componentProperty, String htmlAttrName, String value)
+            throws IOException
+    {
+        if (!isDefaultStringAttributeValue(value))
+        {
+            writer.writeAttribute(htmlAttrName, value, componentProperty);
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     * Check if the value is the default for String type attributes (null or "").
+     * 
+     * @param value
+     * @return
+     */
+    private static final boolean isDefaultStringAttributeValue(String value)
+    {
+        if (value == null)
+        {
+            return true;
+        }
+        else if (value.length() == 0)
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    
+    public static boolean renderHTMLStringNoStyleAttributes(ResponseWriter writer,
+            UIComponent component, String[] attributes) throws IOException
+    {
+        boolean somethingDone = false;
+        for (int i = 0, len = attributes.length; i < len; i++)
+        {
+            String attrName = attributes[i];
+            if (renderHTMLStringAttribute(writer, component, attrName, attrName))
+            {
+                somethingDone = true;
+            }
+        }
+        return somethingDone;
+    }
+
+    public static void writeIdAndName(ResponseWriter writer, UIComponent component, FacesContext facesContext)
             throws IOException
     {
         String clientId = component.getClientId(facesContext);
@@ -867,8 +990,7 @@ public final class HtmlRendererUtils
         renderDisplayValueOnlyForSelects(facesContext, uiComponent, false);
     }
 
-    public static void renderDisplayValueOnlyForSelects(
-            FacesContext facesContext, UIComponent uiComponent,
+    public static void renderDisplayValueOnlyForSelects(FacesContext facesContext, UIComponent uiComponent,
             boolean considerValueType) throws IOException
     {
         ResponseWriter writer = facesContext.getResponseWriter();
@@ -910,8 +1032,7 @@ public final class HtmlRendererUtils
                         uiComponent);
             }
 
-            writer.startElement(isSelectOne ? HTML.SPAN_ELEM : HTML.UL_ELEM,
-                    uiComponent);
+            writer.startElement(isSelectOne ? HTML.SPAN_ELEM : HTML.UL_ELEM, uiComponent);
             writeIdIfNecessary(writer, uiComponent, facesContext);
 
             renderDisplayValueOnlyAttributes(uiComponent, writer);
@@ -936,8 +1057,7 @@ public final class HtmlRendererUtils
         if (!(uiComponent instanceof org.apache.myfaces.shared.component.DisplayValueOnlyCapable))
         {
             log.severe("Wrong type of uiComponent. needs DisplayValueOnlyCapable.");
-            renderHTMLAttributes(writer, uiComponent,
-                    HTML.COMMON_PASSTROUGH_ATTRIBUTES);
+            renderHTMLAttributes(writer, uiComponent, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
 
             return;
         }
@@ -947,33 +1067,27 @@ public final class HtmlRendererUtils
         {
             if (getDisplayValueOnlyStyle(uiComponent) != null)
             {
-                writer.writeAttribute(HTML.STYLE_ATTR,
-                        getDisplayValueOnlyStyle(uiComponent), null);
+                writer.writeAttribute(HTML.STYLE_ATTR, getDisplayValueOnlyStyle(uiComponent), null);
             }
             else if (uiComponent.getAttributes().get("style") != null)
             {
-                writer.writeAttribute(HTML.STYLE_ATTR, uiComponent
-                        .getAttributes().get("style"), null);
+                writer.writeAttribute(HTML.STYLE_ATTR, uiComponent.getAttributes().get("style"), null);
             }
 
             if (getDisplayValueOnlyStyleClass(uiComponent) != null)
             {
-                writer.writeAttribute(HTML.CLASS_ATTR,
-                        getDisplayValueOnlyStyleClass(uiComponent), null);
+                writer.writeAttribute(HTML.CLASS_ATTR, getDisplayValueOnlyStyleClass(uiComponent), null);
             }
             else if (uiComponent.getAttributes().get("styleClass") != null)
             {
-                writer.writeAttribute(HTML.CLASS_ATTR, uiComponent
-                        .getAttributes().get("styleClass"), null);
+                writer.writeAttribute(HTML.CLASS_ATTR, uiComponent.getAttributes().get("styleClass"), null);
             }
 
-            renderHTMLAttributes(writer, uiComponent,
-                    HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_STYLE);
+            renderHTMLAttributes(writer, uiComponent, HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_STYLE);
         }
         else
         {
-            renderHTMLAttributes(writer, uiComponent,
-                    HTML.COMMON_PASSTROUGH_ATTRIBUTES);
+            renderHTMLAttributes(writer, uiComponent, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
         }
     }
 
@@ -989,8 +1103,7 @@ public final class HtmlRendererUtils
 
             if (selectItem instanceof SelectItemGroup)
             {
-                SelectItem[] selectItems = ((SelectItemGroup) selectItem)
-                        .getSelectItems();
+                SelectItem[] selectItems = ((SelectItemGroup) selectItem).getSelectItems();
                 renderSelectOptionsAsText(context, component, converter,
                         lookupSet, Arrays.asList(selectItems), isSelectOne);
             }
@@ -1046,11 +1159,9 @@ public final class HtmlRendererUtils
         }
         else
         {
-            captionClass = (String) component
-                    .getAttributes()
+            captionClass = (String) component.getAttributes()
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.CAPTION_CLASS_ATTR);
-            captionStyle = (String) component
-                    .getAttributes()
+            captionStyle = (String) component.getAttributes()
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.CAPTION_STYLE_ATTR);
         }
         HtmlRendererUtils.writePrettyLineSeparator(context);
@@ -1125,15 +1236,13 @@ public final class HtmlRendererUtils
         {
             if (((DisplayValueOnlyCapable) component).isSetDisplayValueOnly())
             {
-                return ((DisplayValueOnlyCapable) component)
-                        .isDisplayValueOnly();
+                return ((DisplayValueOnlyCapable) component).isDisplayValueOnly();
             }
             UIComponent parent = component;
             while ((parent = parent.getParent()) != null)
             {
                 if (parent instanceof DisplayValueOnlyCapable
-                        && ((DisplayValueOnlyCapable) parent)
-                                .isSetDisplayValueOnly())
+                        && ((DisplayValueOnlyCapable) parent).isSetDisplayValueOnly())
                 {
                     return ((org.apache.myfaces.shared.component.DisplayValueOnlyCapable) parent)
                             .isDisplayValueOnly();
@@ -1147,8 +1256,7 @@ public final class HtmlRendererUtils
             UIInput input) throws IOException
     {
         ResponseWriter writer = facesContext.getResponseWriter();
-        writer.startElement(
-                org.apache.myfaces.shared.renderkit.html.HTML.SPAN_ELEM, input);
+        writer.startElement(org.apache.myfaces.shared.renderkit.html.HTML.SPAN_ELEM, input);
         writeIdIfNecessary(writer, input, facesContext);
         renderDisplayValueOnlyAttributes(input, writer);
         String strValue = RendererUtils.getStringValue(facesContext, input);
@@ -1157,7 +1265,7 @@ public final class HtmlRendererUtils
     }
 
     public static void appendClearHiddenCommandFormParamsFunctionCall(
-            StringBuffer buf, String formName)
+            StringBuilder buf, String formName)
     {
         HtmlJavaScriptUtils.appendClearHiddenCommandFormParamsFunctionCall(buf, formName);
     }
@@ -1173,7 +1281,7 @@ public final class HtmlRendererUtils
      * Adds the hidden form input value assignment that is necessary for the autoscroll
      * feature to an html link or button onclick attribute.
      */
-    public static void appendAutoScrollAssignment(StringBuffer onClickValue,
+    public static void appendAutoScrollAssignment(StringBuilder onClickValue,
             String formName)
     {
         HtmlJavaScriptUtils.appendAutoScrollAssignment(onClickValue, formName);
@@ -1184,7 +1292,7 @@ public final class HtmlRendererUtils
      * feature to an html link or button onclick attribute.
      */
     public static void appendAutoScrollAssignment(FacesContext context,
-            StringBuffer onClickValue, String formName)
+            StringBuilder onClickValue, String formName)
     {
         HtmlJavaScriptUtils.appendAutoScrollAssignment(context, onClickValue, formName);
     }
@@ -1217,19 +1325,14 @@ public final class HtmlRendererUtils
         Boolean value = null;
         if (fc != null)
         {
-            value = (Boolean) fc.getExternalContext().getRequestMap()
-                    .get(ALLOW_CDATA_SECTION_ON);
+            value = (Boolean) fc.getExternalContext().getRequestMap().get(ALLOW_CDATA_SECTION_ON);
         }
         return value != null && ((Boolean) value).booleanValue();
     }
 
-    public static void allowCdataSection(FacesContext fc,
-            boolean cdataSectionAllowed)
+    public static void allowCdataSection(FacesContext fc, boolean cdataSectionAllowed)
     {
-        fc.getExternalContext()
-                .getRequestMap()
-                .put(ALLOW_CDATA_SECTION_ON,
-                        Boolean.valueOf(cdataSectionAllowed));
+        fc.getExternalContext().getRequestMap().put(ALLOW_CDATA_SECTION_ON, Boolean.valueOf(cdataSectionAllowed));
     }
 
     public static class LinkParameter
@@ -1301,13 +1404,11 @@ public final class HtmlRendererUtils
         String labelClass = null;
         if (disabled)
         {
-            labelClass = (String) component.getAttributes().get(
-                    JSFAttr.DISABLED_CLASS_ATTR);
+            labelClass = (String) component.getAttributes().get(JSFAttr.DISABLED_CLASS_ATTR);
         }
         else
         {
-            labelClass = (String) component
-                    .getAttributes()
+            labelClass = (String) component.getAttributes()
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.ENABLED_CLASS_ATTR);
         }
         if (labelClass != null)
@@ -1334,13 +1435,11 @@ public final class HtmlRendererUtils
         String labelClass = null;
         if (disabled)
         {
-            labelClass = (String) component.getAttributes().get(
-                    JSFAttr.DISABLED_CLASS_ATTR);
+            labelClass = (String) component.getAttributes().get(JSFAttr.DISABLED_CLASS_ATTR);
         }
         else
         {
-            labelClass = (String) component
-                    .getAttributes()
+            labelClass = (String) component.getAttributes()
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.ENABLED_CLASS_ATTR);
         }
         if (labelClass != null)
@@ -1377,25 +1476,21 @@ public final class HtmlRendererUtils
         String labelClass = null;
         if (disabled)
         {
-            labelClass = (String) component.getAttributes().get(
-                    JSFAttr.DISABLED_CLASS_ATTR);
+            labelClass = (String) component.getAttributes().get(JSFAttr.DISABLED_CLASS_ATTR);
         }
         else
         {
-            labelClass = (String) component
-                    .getAttributes()
+            labelClass = (String) component.getAttributes()
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.ENABLED_CLASS_ATTR);
         }
         String labelSelectedClass = null;
         if (selected)
         {
-            labelSelectedClass = (String) component.getAttributes().get(
-                    JSFAttr.SELECTED_CLASS_ATTR);
+            labelSelectedClass = (String) component.getAttributes().get(JSFAttr.SELECTED_CLASS_ATTR);
         }
         else
         {
-            labelSelectedClass = (String) component.getAttributes().get(
-                    JSFAttr.UNSELECTED_CLASS_ATTR);
+            labelSelectedClass = (String) component.getAttributes().get(JSFAttr.UNSELECTED_CLASS_ATTR);
         }
         if (labelSelectedClass != null)
         {
@@ -1488,16 +1583,14 @@ public final class HtmlRendererUtils
         {
             return HIDDEN_COMMANDLINK_FIELD_NAME_TRINIDAD;
         }
-        return formInfo.getFormName()
-                + UINamingContainer.getSeparatorChar(FacesContext
+        return formInfo.getFormName() + UINamingContainer.getSeparatorChar(FacesContext
                         .getCurrentInstance()) + HIDDEN_COMMANDLINK_FIELD_NAME;
     }
 
     public static boolean isPartialOrBehaviorSubmit(FacesContext facesContext,
             String clientId)
     {
-        Map<String, String> params = facesContext.getExternalContext()
-                .getRequestParameterMap();
+        Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap();
         String sourceId = params.get("javax.faces.source");
         if (sourceId == null || !sourceId.equals(clientId))
         {
@@ -1507,8 +1600,7 @@ public final class HtmlRendererUtils
         String behaviorEvent = params.get("javax.faces.behavior.event");
         if (behaviorEvent != null)
         {
-            partialOrBehaviorSubmit = ClientBehaviorEvents.ACTION
-                    .equals(behaviorEvent);
+            partialOrBehaviorSubmit = ClientBehaviorEvents.ACTION.equals(behaviorEvent);
             if (partialOrBehaviorSubmit)
             {
                 return partialOrBehaviorSubmit;
@@ -1517,8 +1609,7 @@ public final class HtmlRendererUtils
         String partialEvent = params.get("javax.faces.partial.event");
         if (partialEvent != null)
         {
-            partialOrBehaviorSubmit = ClientBehaviorEvents.CLICK
-                    .equals(partialEvent);
+            partialOrBehaviorSubmit = ClientBehaviorEvents.CLICK.equals(partialEvent);
         }
         return partialOrBehaviorSubmit;
     }
@@ -1531,9 +1622,7 @@ public final class HtmlRendererUtils
     public static String getHiddenCommandLinkFieldNameMyfacesOld(
             FormInfo formInfo)
     {
-        return formInfo.getFormName()
-                + UINamingContainer.getSeparatorChar(FacesContext
-                        .getCurrentInstance())
+        return formInfo.getFormName() + UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance())
                 + HIDDEN_COMMANDLINK_FIELD_NAME_MYFACES_OLD;
     }
 
@@ -1545,8 +1634,7 @@ public final class HtmlRendererUtils
                 : outcome;
         outcome = ((outcome == null) ? STR_EMPTY : outcome.trim());
         // Get the correct URL for the outcome.
-        NavigationHandler nh = facesContext.getApplication()
-                .getNavigationHandler();
+        NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
         if (!(nh instanceof ConfigurableNavigationHandler))
         {
             throw new FacesException(
@@ -1570,11 +1658,15 @@ public final class HtmlRendererUtils
         // handle URL parameters
         if (component.getChildCount() > 0)
         {
-            parameters = new HashMap<String, List<String>>();
             List<UIParameter> validParams = getValidUIParameterChildren(
                     facesContext, component.getChildren(), true, false);
-            for (UIParameter param : validParams)
+            if (validParams.size() > 0)
             {
+                parameters = new HashMap<String, List<String>>();
+            }
+            for (int i = 0, size = validParams.size(); i < size; i++)
+            {
+                UIParameter param = validParams.get(i);
                 String name = param.getName();
                 Object value = param.getValue();
                 if (parameters.containsKey(name))
@@ -1615,14 +1707,10 @@ public final class HtmlRendererUtils
         // In theory the precedence order to deal with params is this:
         // component parameters, navigation-case parameters, view parameters
         // getBookmarkableURL deal with this details.
-        ViewHandler viewHandler = facesContext.getApplication()
-                .getViewHandler();
-        String href = viewHandler.getBookmarkableURL(
-                facesContext,
+        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+        String href = viewHandler.getBookmarkableURL(facesContext,
                 navigationCase.getToViewId(facesContext),
-                parameters,
-                navigationCase.isIncludeViewParams()
-                        || component.isIncludeViewParams());
+                parameters, navigationCase.isIncludeViewParams() || component.isIncludeViewParams());
         // handle fragment (viewId#fragment)
         String fragment = (String) component.getAttributes().get("fragment");
         if (fragment != null)
@@ -1671,8 +1759,7 @@ public final class HtmlRendererUtils
                 // "application/vnd.wap.mms-message,*/*" ,
                 // so this is bug of the client. Anyway, this is a workaround ...
                 if (contentTypeListString != null
-                        && contentTypeListString
-                                .startsWith("application/vnd.wap.mms-message;*/*"))
+                        && contentTypeListString.startsWith("application/vnd.wap.mms-message;*/*"))
                 {
                     contentTypeListString = "*/*";
                 }
@@ -1769,8 +1856,7 @@ public final class HtmlRendererUtils
         {
             return null;
         }
-        return (String) component.getAttributes().get(
-                JSFAttr.JAVASCRIPT_LOCATION);
+        return (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
     }
 
     public static String getImageLocation(UIComponent component)
@@ -1816,8 +1902,7 @@ public final class HtmlRendererUtils
         List<ClientBehaviorContext.Parameter> paramList = null;
         if (params != null)
         {
-            paramList = new ArrayList<ClientBehaviorContext.Parameter>(
-                    params.size());
+            paramList = new ArrayList<ClientBehaviorContext.Parameter>(params.size());
             for (Map.Entry<String, String> paramEntry : params.entrySet())
             {
                 paramList.add(new ClientBehaviorContext.Parameter(paramEntry
@@ -1886,42 +1971,57 @@ public final class HtmlRendererUtils
                 .createClientBehaviorContext(facesContext, uiComponent,
                         eventName, targetClientId, params);
         boolean submitting = false;
-        Iterator<ClientBehavior> clientIterator = attachedEventBehaviors
-                .iterator();
-        while (clientIterator.hasNext())
-        {
-            ClientBehavior clientBehavior = clientIterator.next();
-            String script = clientBehavior.getScript(context);
-            // The script _can_ be null, and in fact is for <f:ajax disabled="true" />
-            if (script != null)
-            {
-                //either strings or functions, but I assume string is more appropriate 
-                //since it allows access to the
-                //origin as this!
-                target.append("'" + escapeJavaScriptForChain(script) + "'");
-                if (clientIterator.hasNext())
-                {
-                    target.append(", ");
-                }
+        
+        // List<ClientBehavior>  attachedEventBehaviors is  99% _DeltaList created in
+        // javax.faces.component.UIComponentBase.addClientBehavior
+        if (attachedEventBehaviors instanceof RandomAccess)
+        {
+            for (int i = 0, size = attachedEventBehaviors.size(); i < size; i++)
+            {
+                ClientBehavior clientBehavior = attachedEventBehaviors.get(i);
+                submitting =  _appendClientBehaviourScript(target, context, 
+                        submitting, i < (size -1), clientBehavior);   
             }
-            if (!submitting)
+        }
+        else 
+        {
+            Iterator<ClientBehavior> clientIterator = attachedEventBehaviors.iterator();
+            while (clientIterator.hasNext())
+            {
+                ClientBehavior clientBehavior = clientIterator.next();
+                submitting = _appendClientBehaviourScript(target, context, submitting, 
+                        clientIterator.hasNext(), clientBehavior);
+            }
+        }
+        
+        return submitting;
+    }
+
+    private static boolean _appendClientBehaviourScript(ScriptContext target, ClientBehaviorContext context, 
+            boolean submitting, boolean hasNext, ClientBehavior clientBehavior)
+    {
+        String script = clientBehavior.getScript(context);
+        // The script _can_ be null, and in fact is for <f:ajax disabled="true" />
+        if (script != null)
+        {
+            //either strings or functions, but I assume string is more appropriate 
+            //since it allows access to the
+            //origin as this!
+            target.append("'" + escapeJavaScriptForChain(script) + "'");
+            if (hasNext)
             {
-                submitting = clientBehavior.getHints().contains(
-                        ClientBehaviorHint.SUBMITTING);
+                target.append(", ");
             }
         }
+        if (!submitting)
+        {
+            submitting = clientBehavior.getHints().contains(
+                    ClientBehaviorHint.SUBMITTING);
+        }
         return submitting;
     }
 
     /**
-     * @param facesContext
-     * @param uiComponent
-     * @param clientBehaviors
-     * @param eventName
-     * @param userEventCode
-     * @param serverEventCode
-     * @param params
-     * @return
      * @since 4.0.0
      */
     public static String buildBehaviorChain(FacesContext facesContext,
@@ -1941,7 +2041,6 @@ public final class HtmlRendererUtils
             Map<String, List<ClientBehavior>> clientBehaviors,
             String userEventCode, String serverEventCode)
     {
-
         ExternalContext externalContext = facesContext.getExternalContext();
         boolean renderCode = JavascriptUtils
                 .isJavascriptAllowed(externalContext);
@@ -1954,8 +2053,7 @@ public final class HtmlRendererUtils
         {
             // escape every ' in the user event code since it will
             // be a string attribute of jsf.util.chain
-            finalParams
-                    .add('\'' + escapeJavaScriptForChain(userEventCode) + '\'');
+            finalParams.add('\'' + escapeJavaScriptForChain(userEventCode) + '\'');
         }
         final MyfacesConfig currentInstance = MyfacesConfig
                 .getCurrentInstance(externalContext);
@@ -1995,7 +2093,6 @@ public final class HtmlRendererUtils
         }
 
         return retVal.toString();
-
     }
 
     /**
@@ -2032,7 +2129,6 @@ public final class HtmlRendererUtils
             Map<String, List<ClientBehavior>> clientBehaviors,
             String userEventCode, String serverEventCode)
     {
-
         ExternalContext externalContext = facesContext.getExternalContext();
         boolean renderCode = JavascriptUtils
                 .isJavascriptAllowed(externalContext);
@@ -2043,8 +2139,7 @@ public final class HtmlRendererUtils
         List<String> finalParams = new ArrayList<String>(3);
         if (userEventCode != null && !userEventCode.trim().equals(STR_EMPTY))
         {
-            finalParams
-                    .add('\'' + escapeJavaScriptForChain(userEventCode) + '\'');
+            finalParams.add('\'' + escapeJavaScriptForChain(userEventCode) + '\'');
         }
 
         final MyfacesConfig currentInstance = MyfacesConfig
@@ -2067,8 +2162,7 @@ public final class HtmlRendererUtils
         if (serverEventCode != null
                 && !serverEventCode.trim().equals(STR_EMPTY))
         {
-            finalParams
-                    .add('\'' + escapeJavaScriptForChain(serverEventCode) + '\'');
+            finalParams.add('\'' + escapeJavaScriptForChain(serverEventCode) + '\'');
         }
         Iterator<String> it = finalParams.iterator();
         // It's possible that there are no behaviors to render.  For example, if we have
@@ -2115,11 +2209,6 @@ public final class HtmlRendererUtils
         return HtmlJavaScriptUtils.escapeJavaScriptForChain(javaScript);
     }
 
-    /**
-     * @param facesContext
-     * @param uiComponent
-     * @return
-     */
     public static Map<String, String> mapAttachedParamsToStringValues(
             FacesContext facesContext, UIComponent uiComponent)
     {
@@ -2128,8 +2217,9 @@ public final class HtmlRendererUtils
         {
             List<UIParameter> validParams = getValidUIParameterChildren(
                     facesContext, uiComponent.getChildren(), true, true);
-            for (UIParameter param : validParams)
+            for (int i = 0, size = validParams.size(); i < size; i++)
             {
+                UIParameter param = validParams.get(i);
                 String name = param.getName();
                 Object value = param.getValue();
                 if (retVal == null)
@@ -2160,7 +2250,7 @@ public final class HtmlRendererUtils
      * @param children
      * @param skipNullValue
      * @param skipUnrendered
-     * @return
+     * @return ArrayList size > 0 if any parameter found
      */
     public static List<UIParameter> getValidUIParameterChildren(
             FacesContext facesContext, List<UIComponent> children,
@@ -2185,7 +2275,7 @@ public final class HtmlRendererUtils
      * @param skipUnrendered should UIParameters with isRendered() returning false be skipped
      * @param skipNullName   should UIParameters with a null name be skipped
      *                       (normally true, but in the case of h:outputFormat false)
-     * @return
+     * @return ArrayList size > 0 if any parameter found 
      */
     public static List<UIParameter> getValidUIParameterChildren(
             FacesContext facesContext, List<UIComponent> children,
@@ -2200,8 +2290,7 @@ public final class HtmlRendererUtils
                 UIParameter param = (UIParameter) child;
                 // check for the disable attribute (since 2.0)
                 // and the render attribute (only if skipUnrendered is true)
-                if (param.isDisable()
-                        || (skipUnrendered && !param.isRendered()))
+                if (param.isDisable() || (skipUnrendered && !param.isRendered()))
                 {
                     // ignore this UIParameter and continue
                     continue;
@@ -2211,9 +2300,7 @@ public final class HtmlRendererUtils
                 if (skipNullName && (name == null || STR_EMPTY.equals(name)))
                 {
                     // warn for a null-name
-                    log.log(Level.WARNING,
-                            "The UIParameter "
-                                    + RendererUtils.getPathToComponent(param)
+                    log.log(Level.WARNING, "The UIParameter " + RendererUtils.getPathToComponent(param)
                                     + " has a name of null or empty string and thus will not be added to the URL.");
                     // and skip it
                     continue;
@@ -2224,10 +2311,7 @@ public final class HtmlRendererUtils
                     if (facesContext.isProjectStage(ProjectStage.Development))
                     {
                         // inform the user about the null value when in Development stage
-                        log.log(Level.INFO,
-                                "The UIParameter "
-                                        + RendererUtils
-                                                .getPathToComponent(param)
+                        log.log(Level.INFO, "The UIParameter " + RendererUtils.getPathToComponent(param)
                                         + " has a value of null and thus will not be added to the URL.");
                     }
                     // skip a null-value
@@ -2270,8 +2354,7 @@ public final class HtmlRendererUtils
             throws IOException
     {
         return renderBehaviorizedAttribute(facesContext, writer,
-                componentProperty, component, eventName, clientBehaviors,
-                componentProperty);
+                componentProperty, component, eventName, clientBehaviors, componentProperty);
     }
 
     public static boolean renderBehaviorizedAttribute(
@@ -2282,8 +2365,7 @@ public final class HtmlRendererUtils
             throws IOException
     {
         return renderBehaviorizedAttribute(facesContext, writer,
-                componentProperty, component, targetClientId, eventName,
-                clientBehaviors, componentProperty);
+                componentProperty, component, targetClientId, eventName, clientBehaviors, componentProperty);
     }
 
     /**
@@ -2310,21 +2392,17 @@ public final class HtmlRendererUtils
     {
         return renderBehaviorizedAttribute(facesContext, writer,
                 componentProperty, component, eventName, null, clientBehaviors,
-                htmlAttrName,
-                (String) component.getAttributes().get(componentProperty));
+                htmlAttrName, (String) component.getAttributes().get(componentProperty));
     }
 
     public static boolean renderBehaviorizedAttribute(
-            FacesContext facesContext, ResponseWriter writer,
-            String componentProperty, UIComponent component,
-            String targetClientId, String eventName,
-            Map<String, List<ClientBehavior>> clientBehaviors,
+            FacesContext facesContext, ResponseWriter writer, String componentProperty, UIComponent component,
+            String targetClientId, String eventName, Map<String, List<ClientBehavior>> clientBehaviors,
             String htmlAttrName) throws IOException
     {
         return renderBehaviorizedAttribute(facesContext, writer,
                 componentProperty, component, targetClientId, eventName, null,
-                clientBehaviors, htmlAttrName, (String) component
-                        .getAttributes().get(componentProperty));
+                clientBehaviors, htmlAttrName, (String) component.getAttributes().get(componentProperty));
     }
 
     /**
@@ -2367,13 +2445,11 @@ public final class HtmlRendererUtils
 
         List<ClientBehavior> cbl = (clientBehaviors != null) ? clientBehaviors
                 .get(eventName) : null;
-
         if (cbl == null || cbl.size() == 0)
         {
             return renderHTMLAttribute(writer, componentProperty, htmlAttrName,
                     attributeValue);
         }
-
         if (cbl.size() > 1 || (cbl.size() == 1 && attributeValue != null))
         {
             return renderHTMLAttribute(writer, componentProperty, htmlAttrName,
@@ -2386,9 +2462,7 @@ public final class HtmlRendererUtils
         {
             //Only 1 behavior and attrValue == null, so just render it directly
             return renderHTMLAttribute(
-                    writer,
-                    componentProperty,
-                    htmlAttrName,
+                    writer, componentProperty, htmlAttrName,
                     cbl.get(0).getScript(
                             ClientBehaviorContext.createClientBehaviorContext(
                                     facesContext, component, eventName,
@@ -2441,7 +2515,6 @@ public final class HtmlRendererUtils
 
         List<ClientBehavior> cbl = (clientBehaviors != null) ? clientBehaviors
                 .get(eventName) : null;
-
         if (((cbl != null) ? cbl.size() : 0) + (attributeValue != null ? 1 : 0)
                 + (serverSideScript != null ? 1 : 0) <= 1)
         {
@@ -2449,21 +2522,19 @@ public final class HtmlRendererUtils
             {
                 if (attributeValue != null)
                 {
-                    return renderHTMLAttribute(writer, componentProperty,
+                    return renderHTMLStringAttribute(writer, componentProperty,
                             htmlAttrName, attributeValue);
                 }
                 else
                 {
-                    return renderHTMLAttribute(writer, componentProperty,
+                    return renderHTMLStringAttribute(writer, componentProperty,
                             htmlAttrName, serverSideScript);
                 }
             }
             else
             {
-                return renderHTMLAttribute(
-                        writer,
-                        componentProperty,
-                        htmlAttrName,
+                return renderHTMLStringAttribute(
+                        writer, componentProperty, htmlAttrName,
                         cbl.get(0).getScript(
                                 ClientBehaviorContext
                                         .createClientBehaviorContext(
@@ -2474,7 +2545,7 @@ public final class HtmlRendererUtils
         }
         else
         {
-            return renderHTMLAttribute(writer, componentProperty, htmlAttrName,
+            return renderHTMLStringAttribute(writer, componentProperty, htmlAttrName,
                     HtmlRendererUtils.buildBehaviorChain(facesContext,
                             component, targetClientId, eventName,
                             eventParameters, clientBehaviors, attributeValue,
@@ -2482,22 +2553,6 @@ public final class HtmlRendererUtils
         }
     }
 
-    /**
-     * @param facesContext
-     * @param writer
-     * @param componentProperty
-     * @param component
-     * @param eventName
-     * @param eventParameters
-     * @param eventName2
-     * @param eventParameters2
-     * @param clientBehaviors
-     * @param htmlAttrName
-     * @param attributeValue
-     * @param serverSideScript
-     * @return
-     * @throws IOException
-     */
     public static boolean renderBehaviorizedAttribute(
             FacesContext facesContext, ResponseWriter writer,
             String componentProperty, UIComponent component, String eventName,
@@ -2530,28 +2585,24 @@ public final class HtmlRendererUtils
                 .get(eventName) : null;
         List<ClientBehavior> cb2 = (clientBehaviors != null) ? clientBehaviors
                 .get(eventName2) : null;
-
         if (((cb1 != null) ? cb1.size() : 0) + ((cb2 != null) ? cb2.size() : 0)
                 + (attributeValue != null ? 1 : 0) <= 1)
         {
             if (attributeValue != null)
             {
-                return renderHTMLAttribute(writer, componentProperty,
+                return renderHTMLStringAttribute(writer, componentProperty,
                         htmlAttrName, attributeValue);
             }
             else if (serverSideScript != null)
             {
-                return renderHTMLAttribute(writer, componentProperty,
+                return renderHTMLStringAttribute(writer, componentProperty,
                         htmlAttrName, serverSideScript);
             }
             else if (((cb1 != null) ? cb1.size() : 0) > 0)
             {
-                return renderHTMLAttribute(
-                        writer,
-                        componentProperty,
-                        htmlAttrName,
-                        cb1.get(0).getScript(
-                                ClientBehaviorContext
+                return renderHTMLStringAttribute(
+                        writer, componentProperty, htmlAttrName,
+                        cb1.get(0).getScript(ClientBehaviorContext
                                         .createClientBehaviorContext(
                                                 facesContext, component,
                                                 eventName, targetClientId,
@@ -2559,12 +2610,9 @@ public final class HtmlRendererUtils
             }
             else
             {
-                return renderHTMLAttribute(
-                        writer,
-                        componentProperty,
-                        htmlAttrName,
-                        cb2.get(0).getScript(
-                                ClientBehaviorContext
+                return renderHTMLStringAttribute(
+                        writer, componentProperty, htmlAttrName,
+                        cb2.get(0).getScript(ClientBehaviorContext
                                         .createClientBehaviorContext(
                                                 facesContext, component,
                                                 eventName2, targetClientId,
@@ -2573,7 +2621,7 @@ public final class HtmlRendererUtils
         }
         else
         {
-            return renderHTMLAttribute(writer, componentProperty, htmlAttrName,
+            return renderHTMLStringAttribute(writer, componentProperty, htmlAttrName,
                     HtmlRendererUtils.buildBehaviorChain(facesContext,
                             component, targetClientId, eventName,
                             eventParameters, eventName2, eventParameters2,
@@ -2582,11 +2630,6 @@ public final class HtmlRendererUtils
     }
 
     /**
-     * @param facesContext
-     * @param writer
-     * @param uiComponent
-     * @param clientBehaviors
-     * @throws IOException
      * @since 4.0.0
      */
     public static void renderBehaviorizedEventHandlers(
@@ -2641,11 +2684,6 @@ public final class HtmlRendererUtils
     }
 
     /**
-     * @param facesContext
-     * @param writer
-     * @param uiComponent
-     * @param clientBehaviors
-     * @throws IOException
      * @since 4.0.0
      */
     public static void renderBehaviorizedEventHandlersWithoutOnclick(
@@ -2721,11 +2759,6 @@ public final class HtmlRendererUtils
     }
 
     /**
-     * @param facesContext
-     * @param writer
-     * @param uiComponent
-     * @param clientBehaviors
-     * @throws IOException
      * @since 4.0.0
      */
     public static void renderBehaviorizedFieldEventHandlers(
@@ -2735,17 +2768,13 @@ public final class HtmlRendererUtils
             throws IOException
     {
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
-                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors,
-                HTML.ONFOCUS_ATTR);
+                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors, HTML.ONFOCUS_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
-                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors,
-                HTML.ONBLUR_ATTR);
+                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors, HTML.ONBLUR_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONCHANGE_ATTR,
-                uiComponent, ClientBehaviorEvents.CHANGE, clientBehaviors,
-                HTML.ONCHANGE_ATTR);
+                uiComponent, ClientBehaviorEvents.CHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
-                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors,
-                HTML.ONSELECT_ATTR);
+                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors, HTML.ONSELECT_ATTR);
     }
 
     public static void renderBehaviorizedFieldEventHandlersWithoutOnfocus(
@@ -2755,22 +2784,14 @@ public final class HtmlRendererUtils
             throws IOException
     {
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
-                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors,
-                HTML.ONBLUR_ATTR);
+                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors, HTML.ONBLUR_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONCHANGE_ATTR,
-                uiComponent, ClientBehaviorEvents.CHANGE, clientBehaviors,
-                HTML.ONCHANGE_ATTR);
+                uiComponent, ClientBehaviorEvents.CHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
-                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors,
-                HTML.ONSELECT_ATTR);
+                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors, HTML.ONSELECT_ATTR);
     }
 
     /**
-     * @param facesContext
-     * @param writer
-     * @param uiComponent
-     * @param clientBehaviors
-     * @throws IOException
      * @since 4.0.0
      */
     public static void renderBehaviorizedFieldEventHandlersWithoutOnchange(
@@ -2780,14 +2801,11 @@ public final class HtmlRendererUtils
             throws IOException
     {
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
-                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors,
-                HTML.ONFOCUS_ATTR);
+                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors, HTML.ONFOCUS_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
-                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors,
-                HTML.ONBLUR_ATTR);
+                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors, HTML.ONBLUR_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
-                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors,
-                HTML.ONSELECT_ATTR);
+                uiComponent, ClientBehaviorEvents.SELECT, clientBehaviors, HTML.ONSELECT_ATTR);
     }
 
     public static void renderBehaviorizedFieldEventHandlersWithoutOnchange(
@@ -2797,14 +2815,11 @@ public final class HtmlRendererUtils
             throws IOException
     {
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
-                uiComponent, targetClientId, ClientBehaviorEvents.FOCUS,
-                clientBehaviors, HTML.ONFOCUS_ATTR);
+                uiComponent, targetClientId, ClientBehaviorEvents.FOCUS, clientBehaviors, HTML.ONFOCUS_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
-                uiComponent, targetClientId, ClientBehaviorEvents.BLUR,
-                clientBehaviors, HTML.ONBLUR_ATTR);
+                uiComponent, targetClientId, ClientBehaviorEvents.BLUR, clientBehaviors, HTML.ONBLUR_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
-                uiComponent, targetClientId, ClientBehaviorEvents.SELECT,
-                clientBehaviors, HTML.ONSELECT_ATTR);
+                uiComponent, targetClientId, ClientBehaviorEvents.SELECT, clientBehaviors, HTML.ONSELECT_ATTR);
     }
 
     public static void renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
@@ -2814,20 +2829,12 @@ public final class HtmlRendererUtils
             throws IOException
     {
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
-                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors,
-                HTML.ONFOCUS_ATTR);
+                uiComponent, ClientBehaviorEvents.FOCUS, clientBehaviors, HTML.ONFOCUS_ATTR);
         renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
-                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors,
-                HTML.ONBLUR_ATTR);
+                uiComponent, ClientBehaviorEvents.BLUR, clientBehaviors, HTML.ONBLUR_ATTR);
     }
 
     /**
-     * @param facesContext
-     * @param writer
-     * @param uiComponent
-     * @param clientBehaviors
-     * @return
-     * @throws IOException
      * @since 4.0.0
      */
     public static boolean renderBehaviorizedOnchangeEventHandler(
@@ -2847,29 +2854,26 @@ public final class HtmlRendererUtils
             String chain = HtmlRendererUtils.buildBehaviorChain(facesContext,
                     uiComponent, ClientBehaviorEvents.CHANGE, null,
                     ClientBehaviorEvents.VALUECHANGE, null, clientBehaviors,
-                    (String) uiComponent.getAttributes()
-                            .get(HTML.ONCHANGE_ATTR), null);
+                    (String) uiComponent.getAttributes().get(HTML.ONCHANGE_ATTR), null);
 
-            return HtmlRendererUtils.renderHTMLAttribute(writer,
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer,
                     HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR, chain);
         }
         else if (hasChange)
         {
             return HtmlRendererUtils.renderBehaviorizedAttribute(facesContext,
                     writer, HTML.ONCHANGE_ATTR, uiComponent,
-                    ClientBehaviorEvents.CHANGE, clientBehaviors,
-                    HTML.ONCHANGE_ATTR);
+                    ClientBehaviorEvents.CHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         }
         else if (hasValueChange)
         {
             return HtmlRendererUtils.renderBehaviorizedAttribute(facesContext,
                     writer, HTML.ONCHANGE_ATTR, uiComponent,
-                    ClientBehaviorEvents.VALUECHANGE, clientBehaviors,
-                    HTML.ONCHANGE_ATTR);
+                    ClientBehaviorEvents.VALUECHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         }
         else
         {
-            return HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent,
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer, uiComponent,
                     HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR);
         }
     }
@@ -2892,29 +2896,26 @@ public final class HtmlRendererUtils
                     uiComponent, targetClientId, ClientBehaviorEvents.CHANGE,
                     null, ClientBehaviorEvents.VALUECHANGE, null,
                     clientBehaviors,
-                    (String) uiComponent.getAttributes()
-                            .get(HTML.ONCHANGE_ATTR), null);
+                    (String) uiComponent.getAttributes().get(HTML.ONCHANGE_ATTR), null);
 
-            return HtmlRendererUtils.renderHTMLAttribute(writer,
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer,
                     HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR, chain);
         }
         else if (hasChange)
         {
             return HtmlRendererUtils.renderBehaviorizedAttribute(facesContext,
                     writer, HTML.ONCHANGE_ATTR, uiComponent, targetClientId,
-                    ClientBehaviorEvents.CHANGE, clientBehaviors,
-                    HTML.ONCHANGE_ATTR);
+                    ClientBehaviorEvents.CHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         }
         else if (hasValueChange)
         {
             return HtmlRendererUtils.renderBehaviorizedAttribute(facesContext,
                     writer, HTML.ONCHANGE_ATTR, uiComponent, targetClientId,
-                    ClientBehaviorEvents.VALUECHANGE, clientBehaviors,
-                    HTML.ONCHANGE_ATTR);
+                    ClientBehaviorEvents.VALUECHANGE, clientBehaviors, HTML.ONCHANGE_ATTR);
         }
         else
         {
-            return HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent,
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer, uiComponent,
                     HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR);
         }
     }
@@ -2957,7 +2958,6 @@ public final class HtmlRendererUtils
         messages.setTitle("Project Stage[Development]: Unhandled Messages");
         messages.setStyle("color:orange");
         messages.setRedisplay(false);
-
         // render the component
         messages.encodeAll(facesContext);
     }
@@ -2973,13 +2973,11 @@ public final class HtmlRendererUtils
         {
             super();
         }
-
         public ScriptContext(boolean prettyPrint)
         {
             super(prettyPrint);
         }
-
-        public ScriptContext(StringBuffer buf, boolean prettyPrint)
+        public ScriptContext(StringBuilder buf, boolean prettyPrint)
         {
             super(buf, prettyPrint);
         }

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java?rev=1239799&r1=1239798&r2=1239799&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java Thu Feb  2 20:00:42 2012
@@ -34,7 +34,7 @@ import org.apache.myfaces.shared.renderk
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.renderkit.html.util.UnicodeEncoder;
 import org.apache.myfaces.shared.util.CommentUtils;
-import org.apache.myfaces.shared.util.FastWriter;
+import org.apache.myfaces.shared.util.StreamCharBuffer;
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
@@ -70,7 +70,7 @@ public class HtmlResponseWriterImpl
     /**
      * The writer used to buffer script and style content
      */
-    private FastWriter _bufferedWriter;
+    private StreamCharBuffer _buffer;
     
     private String _contentType;
     
@@ -89,6 +89,7 @@ public class HtmlResponseWriterImpl
     
     private String _characterEncoding;
     private boolean _wrapScriptContentWithXmlCommentTag;
+    private boolean _isUTF8;
     
     private String _startElementName;
     private Boolean _isInsideScript;
@@ -148,7 +149,6 @@ public class HtmlResponseWriterImpl
         _outputWriter = writer;
         //The current writer to be used is the one used as output 
         _currentWriter = _outputWriter;
-        _bufferedWriter = new FastWriter(1024);
         _wrapScriptContentWithXmlCommentTag = wrapScriptContentWithXmlCommentTag;
         
         _contentType = contentType;
@@ -190,6 +190,7 @@ public class HtmlResponseWriterImpl
             // canonize to uppercase, that's the standard format
             _characterEncoding = characterEncoding.toUpperCase();
         }
+        _isUTF8 = UTF8.equals(_characterEncoding);
     }
 
     public static boolean supportsContentType(String contentType)
@@ -328,13 +329,17 @@ public class HtmlResponseWriterImpl
                 }*/
                 if (isScript(_startElementName) && (_isXhtmlContentType || _wrapScriptContentWithXmlCommentTag))
                 {
-                    _bufferedWriter.reset();
-                    _currentWriter = _bufferedWriter;
+                    //_bufferedWriter.reset();
+                    //_currentWriter = _bufferedWriter;
+                    getInternalBuffer(true);
+                    _currentWriter = getInternalBuffer().getWriter();
                 }                
                 if (isStyle(_startElementName) && _isXhtmlContentType)
                 {
-                    _bufferedWriter.reset();
-                    _currentWriter = _bufferedWriter;
+                    //_bufferedWriter.reset();
+                    //_currentWriter = _bufferedWriter;
+                    getInternalBuffer(true);
+                    _currentWriter = getInternalBuffer().getWriter();
                 }
             }
             _startTagOpen = false;
@@ -427,7 +432,7 @@ public class HtmlResponseWriterImpl
     
     private void writeStyleContent() throws IOException
     {
-        String content = _bufferedWriter.toString(); 
+        String content = getInternalBuffer().toString();
         
         if(_isXhtmlContentType)
         {
@@ -476,7 +481,7 @@ public class HtmlResponseWriterImpl
     
     private void writeScriptContent() throws IOException
     {
-        String content = _bufferedWriter.toString();
+        String content = getInternalBuffer().toString();
         String trimmedContent = null;
         
         if(_isXhtmlContentType)
@@ -655,8 +660,8 @@ public class HtmlResponseWriterImpl
             _currentWriter.write(' ');
             _currentWriter.write(name);
             _currentWriter.write("=\"");
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
-                    strValue, false, false, !UTF8.equals(_characterEncoding)));
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(_currentWriter,
+                    strValue, false, false, !_isUTF8);
             _currentWriter.write('"');
         }
     }
@@ -679,8 +684,8 @@ public class HtmlResponseWriterImpl
         _currentWriter.write("=\"");
         if (strValue.toLowerCase().startsWith("javascript:"))
         {
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
-                    strValue, false, false, !UTF8.equals(_characterEncoding)));
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(_currentWriter,
+                    strValue, false, false, !_isUTF8);
         }
         else
         {
@@ -712,9 +717,8 @@ public class HtmlResponseWriterImpl
             }
             */
             //_writer.write(strValue);
-            _currentWriter.write(
-                    org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encodeURIAtributte(
-                            strValue, _characterEncoding));
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encodeURIAtributte(_currentWriter,
+                            strValue, _characterEncoding);
         }
         _currentWriter.write('"');
     }
@@ -746,19 +750,19 @@ public class HtmlResponseWriterImpl
         if (isScriptOrStyle())
         {
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding))
+            if (_isUTF8)
             {
                 _currentWriter.write(strValue);
             }
             else
             {
-                _currentWriter.write(UnicodeEncoder.encode(strValue));
+                UnicodeEncoder.encode(_currentWriter, strValue);
             }
         }
         else
         {
-            _currentWriter.write(org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
-                    strValue, false, false, !UTF8.equals(_characterEncoding)));
+            org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(_currentWriter,
+                      strValue, false, false, !_isUTF8);
         }
     }
 
@@ -779,26 +783,26 @@ public class HtmlResponseWriterImpl
         {
             String strValue = new String(cbuf, off, len);
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding))
+            if (_isUTF8)
             {
                 _currentWriter.write(strValue);
             }
             else
             {
-                _currentWriter.write(UnicodeEncoder.encode(strValue));
+                UnicodeEncoder.encode(_currentWriter, strValue);
             }
         }
         else if (isTextarea())
         {
             // For textareas we must *not* map successive spaces to &nbsp or Newlines to <br/>
             org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
-                    cbuf, off, len, false, false, !UTF8.equals(_characterEncoding), _currentWriter);
+                    cbuf, off, len, false, false, !_isUTF8, _currentWriter);
         }
         else
         {
             // We map successive spaces to &nbsp; and Newlines to <br/>
             org.apache.myfaces.shared.renderkit.html.util.HTMLEncoder.encode(
-                    cbuf, off, len, true, true, !UTF8.equals(_characterEncoding), _currentWriter);
+                    cbuf, off, len, true, true, !_isUTF8, _currentWriter);
         }
     }
 
@@ -896,15 +900,14 @@ public class HtmlResponseWriterImpl
     public void write(char cbuf[], int off, int len) throws IOException
     {
         closeStartTagIfNecessary();
-        String strValue = new String(cbuf, off, len);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding))
+        if (_isUTF8)
         {
-            _currentWriter.write(strValue);
+            _currentWriter.write(cbuf, off, len);
         }
         else
         {
-            _currentWriter.write(UnicodeEncoder.encode(strValue));
+            UnicodeEncoder.encode(_currentWriter, cbuf, off, len);
         }
     }
 
@@ -917,15 +920,14 @@ public class HtmlResponseWriterImpl
     public void write(char cbuf[]) throws IOException
     {
         closeStartTagIfNecessary();
-        String strValue = new String(cbuf);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding))
+        if (_isUTF8)
         {
-            _currentWriter.write(strValue);
+            _currentWriter.write(cbuf);
         }
         else
         {
-            _currentWriter.write(UnicodeEncoder.encode(strValue));
+            UnicodeEncoder.encode(_currentWriter, cbuf, 0, cbuf.length);
         }
     }
 
@@ -937,13 +939,13 @@ public class HtmlResponseWriterImpl
         if (str.length() > 0)
         {
             // Don't bother encoding anything if chosen character encoding is UTF-8
-            if (UTF8.equals(_characterEncoding))
+            if (_isUTF8)
             {
                 _currentWriter.write(str);
             }
             else
             {
-                _currentWriter.write(UnicodeEncoder.encode(str));
+                UnicodeEncoder.encode(_currentWriter, str);
             }
         }
     }
@@ -951,15 +953,14 @@ public class HtmlResponseWriterImpl
     public void write(String str, int off, int len) throws IOException
     {
         closeStartTagIfNecessary();
-        String strValue = str.substring(off, off+len);
         // Don't bother encoding anything if chosen character encoding is UTF-8
-        if (UTF8.equals(_characterEncoding))
+        if (_isUTF8)
         {
-            _currentWriter.write(strValue);
+            _currentWriter.write(str, off, len);
         }
         else
         {
-            _currentWriter.write(UnicodeEncoder.encode(strValue));
+            UnicodeEncoder.encode(_currentWriter, str, off, len);
         }
     }
     
@@ -972,4 +973,22 @@ public class HtmlResponseWriterImpl
     {
         writeText(object,string);
     }
+    
+    protected StreamCharBuffer getInternalBuffer()
+    {
+        return getInternalBuffer(false);
+    }
+    
+    protected StreamCharBuffer getInternalBuffer(boolean reset)
+    {
+        if (_buffer == null)
+        {
+            _buffer = new StreamCharBuffer(256, 100);
+        }
+        else if (reset)
+        {
+            _buffer.reset();
+        }
+        return _buffer;
+    }
 }

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSecretRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSecretRendererBase.java?rev=1239799&r1=1239798&r2=1239799&view=diff
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSecretRendererBase.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlSecretRendererBase.java Thu Feb  2 20:00:42 2012
@@ -117,14 +117,42 @@ public class HtmlSecretRendererBase
         {
             behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
             
-            HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
-            HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
-            HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(
-                    facesContext, writer, uiComponent, behaviors);
+            long commonPropertiesMarked = 0L;
+            if (isCommonPropertiesOptimizationEnabled(facesContext))
+            {
+                commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
+            }
+            if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
+            {
+                CommonPropertyUtils.renderChangeEventProperty(writer, 
+                        commonPropertiesMarked, uiComponent);
+                CommonPropertyUtils.renderEventProperties(writer, 
+                        commonPropertiesMarked, uiComponent);
+                CommonPropertyUtils.renderFieldEventPropertiesWithoutOnchange(writer, 
+                        commonPropertiesMarked, uiComponent);
+            }
+            else
+            {
+                HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
+                if (isCommonEventsOptimizationEnabled(facesContext))
+                {
+                    Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(uiComponent);
+                    CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
+                            commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
+                    CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(
+                        facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
+                }
+                else
+                {
+                    HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
+                    HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(
+                            facesContext, writer, uiComponent, behaviors);
+                }
+            }
             if (isCommonPropertiesOptimizationEnabled(facesContext))
             {
                 CommonPropertyUtils.renderInputPassthroughPropertiesWithoutDisabledAndEvents(writer, 
-                        CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
+                        commonPropertiesMarked, uiComponent);
             }
             else
             {