myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1239799 [3/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/
Date Thu, 02 Feb 2012 20:00:44 GMT
Added: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonEventUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonEventUtils.java?rev=1239799&view=auto
==============================================================================
--- myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonEventUtils.java (added)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonEventUtils.java Thu Feb  2 20:00:42 2012
@@ -0,0 +1,541 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.shared.renderkit.html;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import org.apache.myfaces.shared.renderkit.ClientBehaviorEvents;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public class CommonEventUtils
+{
+    public static long getCommonEventsMarked(UIComponent component)
+    {
+        Long commonEvents = (Long) component.getAttributes().get(CommonEventConstants.COMMON_EVENTS_MARKED);
+        
+        if (commonEvents == null)
+        {
+            commonEvents = 0L;
+        }
+        return commonEvents;
+    }
+        
+    /**
+     * Render an attribute taking into account the passed event and
+     * the component property. It will be rendered as "componentProperty"
+     * attribute.
+     *
+     * @param facesContext
+     * @param writer
+     * @param componentProperty
+     * @param component
+     * @param eventName
+     * @param clientBehaviors
+     * @return
+     * @throws IOException
+     * @since 4.0.1
+     */
+    /*
+    public static boolean renderBehaviorizedAttribute(
+            FacesContext facesContext, ResponseWriter writer,
+            String componentProperty, UIComponent component, String eventName,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        return renderBehaviorizedAttribute(facesContext, writer,
+                componentProperty, component, eventName, clientBehaviors,
+                componentProperty);
+    }
+
+    public static boolean renderBehaviorizedAttribute(
+            FacesContext facesContext, ResponseWriter writer,
+            String componentProperty, UIComponent component,
+            String targetClientId, String eventName,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        return renderBehaviorizedAttribute(facesContext, writer,
+                componentProperty, component, targetClientId, eventName,
+                clientBehaviors, componentProperty);
+    }*/
+
+    /**
+     * Render an attribute taking into account the passed event and
+     * the component property. The event will be rendered on the selected
+     * htmlAttrName
+     *
+     * @param facesContext
+     * @param writer
+     * @param component
+     * @param clientBehaviors
+     * @param eventName
+     * @param componentProperty
+     * @param htmlAttrName
+     * @return
+     * @throws IOException
+     * @since 4.0.1
+     */
+    /*
+    public static boolean renderBehaviorizedAttribute(
+            FacesContext facesContext, ResponseWriter writer,
+            String componentProperty, UIComponent component, String eventName,
+            Map<String, List<ClientBehavior>> clientBehaviors,
+            String htmlAttrName) throws IOException
+    {
+        return renderBehaviorizedAttribute(facesContext, writer,
+                componentProperty, component, eventName, null, clientBehaviors,
+                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,
+            String htmlAttrName) throws IOException
+    {
+        return renderBehaviorizedAttribute(facesContext, writer,
+                componentProperty, component, targetClientId, eventName, null,
+                clientBehaviors, htmlAttrName, (String) component
+                        .getAttributes().get(componentProperty));
+    }
+
+    /**
+     * Render an attribute taking into account the passed event,
+     * the component property and the passed attribute value for the component
+     * property. The event will be rendered on the selected htmlAttrName.
+     *
+     * @param facesContext
+     * @param writer
+     * @param componentProperty
+     * @param component
+     * @param eventName
+     * @param clientBehaviors
+     * @param htmlAttrName
+     * @param attributeValue
+     * @return
+     * @throws IOException
+     */
+    public static boolean renderBehaviorizedAttribute(
+            FacesContext facesContext, ResponseWriter writer,
+            String componentProperty, UIComponent component, String eventName,
+            Collection<ClientBehaviorContext.Parameter> eventParameters,
+            Map<String, List<ClientBehavior>> clientBehaviors,
+            String htmlAttrName, String attributeValue) throws IOException
+    {
+        return renderBehaviorizedAttribute(facesContext, writer,
+                componentProperty, component,
+                component.getClientId(facesContext), eventName,
+                eventParameters, clientBehaviors, htmlAttrName, attributeValue);
+    }
+
+    public static boolean renderBehaviorizedAttribute(
+            FacesContext facesContext, ResponseWriter writer,
+            String componentProperty, UIComponent component,
+            String targetClientId, String eventName,
+            Collection<ClientBehaviorContext.Parameter> eventParameters,
+            Map<String, List<ClientBehavior>> clientBehaviors,
+            String htmlAttrName, String attributeValue) throws IOException
+    {
+
+        List<ClientBehavior> cbl = (clientBehaviors != null) ? clientBehaviors
+                .get(eventName) : null;
+
+        if (cbl == null || cbl.size() == 0)
+        {
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer, componentProperty, htmlAttrName,
+                    attributeValue);
+        }
+
+        if (cbl.size() > 1 || (cbl.size() == 1 && attributeValue != null))
+        {
+            return HtmlRendererUtils.renderHTMLStringAttribute(writer, componentProperty, htmlAttrName,
+                    HtmlRendererUtils.buildBehaviorChain(facesContext,
+                            component, targetClientId, eventName,
+                            eventParameters, clientBehaviors, attributeValue,
+                            HtmlRendererUtils.STR_EMPTY));
+        }
+        else
+        {
+            //Only 1 behavior and attrValue == null, so just render it directly
+            return HtmlRendererUtils.renderHTMLStringAttribute(
+                    writer,
+                    componentProperty,
+                    htmlAttrName,
+                    cbl.get(0).getScript(
+                            ClientBehaviorContext.createClientBehaviorContext(
+                                    facesContext, component, eventName,
+                                    targetClientId, eventParameters)));
+        }
+    }
+
+    public static void renderBehaviorizedEventHandlers(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        renderBehaviorizedEventHandlers(facesContext, writer, 
+                commonPropertiesMarked, commonEventsMarked, uiComponent,
+                uiComponent.getClientId(facesContext), clientBehaviors);
+    }
+    
+    public static void renderBehaviorizedEventHandlers(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONCLICK_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.CLICK_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONCLICK_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.CLICK,
+                    clientBehaviors, HTML.ONCLICK_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONDBLCLICK_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.DBLCLICK_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONDBLCLICK_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.DBLCLICK,
+                    clientBehaviors, HTML.ONDBLCLICK_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEDOWN_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEDOWN_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEDOWN_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEDOWN, clientBehaviors,
+                    HTML.ONMOUSEDOWN_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEUP_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEUP_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEUP_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.MOUSEUP,
+                    clientBehaviors, HTML.ONMOUSEUP_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOVER_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEOVER_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEOVER_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEOVER, clientBehaviors,
+                    HTML.ONMOUSEOVER_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEMOVE_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEMOVE_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEMOVE_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEMOVE, clientBehaviors,
+                    HTML.ONMOUSEMOVE_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOUT_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEOUT_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOUT_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.MOUSEOUT,
+                    clientBehaviors, HTML.ONMOUSEOUT_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYPRESS_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYPRESS_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYPRESS_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYPRESS,
+                    clientBehaviors, HTML.ONKEYPRESS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYDOWN_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYDOWN_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYDOWN_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYDOWN,
+                    clientBehaviors, HTML.ONKEYDOWN_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYUP_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYUP_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYUP_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYUP,
+                    clientBehaviors, HTML.ONKEYUP_ATTR);
+        }
+    }
+
+    public static void renderBehaviorizedEventHandlersWithoutOnclick(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, 
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        renderBehaviorizedEventHandlersWithoutOnclick(facesContext, writer, 
+                commonPropertiesMarked, commonEventsMarked, uiComponent,
+                uiComponent.getClientId(facesContext), clientBehaviors);
+    }
+
+    /**
+     * @param facesContext
+     * @param writer
+     * @param uiComponent
+     * @param clientBehaviors
+     * @throws IOException
+     * @since 4.0.0
+     */
+    public static void renderBehaviorizedEventHandlersWithoutOnclick(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONDBLCLICK_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.DBLCLICK_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONDBLCLICK_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.DBLCLICK,
+                    clientBehaviors, HTML.ONDBLCLICK_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEDOWN_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEDOWN_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEDOWN_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEDOWN, clientBehaviors,
+                    HTML.ONMOUSEDOWN_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEUP_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEUP_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEUP_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.MOUSEUP,
+                    clientBehaviors, HTML.ONMOUSEUP_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOVER_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEOVER_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEOVER_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEOVER, clientBehaviors,
+                    HTML.ONMOUSEOVER_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEMOVE_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEMOVE_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer,
+                    HTML.ONMOUSEMOVE_ATTR, uiComponent, targetClientId,
+                    ClientBehaviorEvents.MOUSEMOVE, clientBehaviors,
+                    HTML.ONMOUSEMOVE_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOUT_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.MOUSEOUT_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOUT_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.MOUSEOUT,
+                    clientBehaviors, HTML.ONMOUSEOUT_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYPRESS_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYPRESS_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYPRESS_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYPRESS,
+                    clientBehaviors, HTML.ONKEYPRESS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYDOWN_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYDOWN_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYDOWN_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYDOWN,
+                    clientBehaviors, HTML.ONKEYDOWN_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYUP_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.KEYUP_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONKEYUP_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.KEYUP,
+                    clientBehaviors, HTML.ONKEYUP_ATTR);
+        }
+    }
+
+    /**
+     * @param facesContext
+     * @param writer
+     * @param uiComponent
+     * @param clientBehaviors
+     * @throws IOException
+     * @since 4.0.0
+     */
+    public static void renderBehaviorizedFieldEventHandlers(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.FOCUS_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.FOCUS, clientBehaviors,
+                    HTML.ONFOCUS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.BLUR_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.BLUR, clientBehaviors,
+                    HTML.ONBLUR_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONCHANGE_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.CHANGE_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONCHANGE_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.CHANGE, clientBehaviors,
+                    HTML.ONCHANGE_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONSELECT_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.SELECT_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.SELECT, clientBehaviors,
+                    HTML.ONSELECT_ATTR);
+        }
+    }
+
+    public static void renderBehaviorizedFieldEventHandlersWithoutOnfocus(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.BLUR_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.BLUR, clientBehaviors,
+                    HTML.ONBLUR_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONCHANGE_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.CHANGE_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONCHANGE_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.CHANGE, clientBehaviors,
+                    HTML.ONCHANGE_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONSELECT_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.SELECT_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.SELECT, clientBehaviors,
+                    HTML.ONSELECT_ATTR);
+        }
+    }
+
+    public static void renderBehaviorizedFieldEventHandlersWithoutOnchange(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, 
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        renderBehaviorizedFieldEventHandlersWithoutOnchange(
+                facesContext, writer, commonPropertiesMarked, commonEventsMarked, 
+                uiComponent, uiComponent.getClientId(facesContext), clientBehaviors);
+    }
+    
+    public static void renderBehaviorizedFieldEventHandlersWithoutOnchange(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.FOCUS_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.FOCUS, clientBehaviors,
+                    HTML.ONFOCUS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.BLUR_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.BLUR, clientBehaviors,
+                    HTML.ONBLUR_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONSELECT_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.SELECT_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONSELECT_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.SELECT, clientBehaviors,
+                    HTML.ONSELECT_ATTR);
+        }
+    }
+
+    public static void renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
+                facesContext, writer, 
+                commonPropertiesMarked, commonEventsMarked, 
+                uiComponent, uiComponent.getClientId(facesContext), 
+                clientBehaviors);
+    }
+    
+    public static void renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
+            FacesContext facesContext, ResponseWriter writer,
+            long commonPropertiesMarked, long commonEventsMarked,
+            UIComponent uiComponent, String targetClientId,
+            Map<String, List<ClientBehavior>> clientBehaviors)
+            throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.FOCUS_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONFOCUS_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.FOCUS, clientBehaviors,
+                    HTML.ONFOCUS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0 ||
+            (commonEventsMarked & CommonEventConstants.BLUR_EVENT) != 0)
+        {
+            renderBehaviorizedAttribute(facesContext, writer, HTML.ONBLUR_ATTR,
+                    uiComponent, targetClientId, ClientBehaviorEvents.BLUR, clientBehaviors,
+                    HTML.ONBLUR_ATTR);
+        }
+    }
+}

Propchange: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonEventUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonPropertyUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonPropertyUtils.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/CommonPropertyUtils.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/CommonPropertyUtils.java Thu Feb  2 20:00:42 2012
@@ -43,32 +43,23 @@ public final class CommonPropertyUtils
         return component.getId() != null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX);
     }
 
-    public static final void renderHTMLStringAttribute(ResponseWriter writer,
-            UIComponent component, String componentProperty, String htmlAttrName)
-            throws IOException
-    {
-        String value = (String) component.getAttributes()
-                .get(componentProperty);
-        writer.writeAttribute(htmlAttrName, value, componentProperty);
-    }
-
     public static final void renderUniversalProperties(ResponseWriter writer,
             long commonPropertiesMarked, UIComponent component)
             throws IOException
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.DIR_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.DIR_ATTR, HTML.DIR_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.LANG_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.LANG_ATTR, HTML.LANG_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.TITLE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.TITLE_ATTR, HTML.TITLE_ATTR);
         }
     }
@@ -79,12 +70,12 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.DIR_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.DIR_ATTR, HTML.DIR_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.LANG_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.LANG_ATTR, HTML.LANG_ATTR);
         }
     }
@@ -95,12 +86,12 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.STYLE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.STYLE_ATTR, HTML.STYLE_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.STYLECLASS_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.STYLE_CLASS_ATTR, HTML.CLASS_ATTR);
         }
     }
@@ -111,7 +102,7 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ONCLICK_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONCLICK_ATTR, HTML.ONCLICK_ATTR);
         }
         renderEventPropertiesWithoutOnclick(writer, commonPropertiesMarked, component);
@@ -123,47 +114,47 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ONDBLCLICK_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONDBLCLICK_ATTR, HTML.ONDBLCLICK_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEDOWN_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONMOUSEDOWN_ATTR, HTML.ONMOUSEDOWN_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEUP_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONMOUSEUP_ATTR, HTML.ONMOUSEUP_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOVER_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONMOUSEOVER_ATTR, HTML.ONMOUSEOVER_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEMOVE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONMOUSEMOVE_ATTR, HTML.ONMOUSEMOVE_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONMOUSEOUT_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONMOUSEOUT_ATTR, HTML.ONMOUSEOUT_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYPRESS_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONKEYPRESS_ATTR, HTML.ONKEYPRESS_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYDOWN_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONKEYDOWN_ATTR, HTML.ONKEYDOWN_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONKEYUP_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONKEYUP_ATTR, HTML.ONKEYUP_ATTR);
         }
     }
@@ -175,12 +166,12 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ONCHANGE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONSELECT_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONSELECT_ATTR, HTML.ONSELECT_ATTR);
         }
     }
@@ -191,28 +182,73 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONFOCUS_ATTR, HTML.ONFOCUS_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ONBLUR_ATTR, HTML.ONBLUR_ATTR);
         }
     }
     
+    public static final void renderFieldEventPropertiesWithoutOnchangeAndOnselect(ResponseWriter writer,
+            long commonPropertiesMarked, UIComponent component) throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONFOCUS_ATTR, HTML.ONFOCUS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONBLUR_ATTR, HTML.ONBLUR_ATTR);
+        }
+    }
+    
+    public static final void renderFieldEventPropertiesWithoutOnchange(ResponseWriter writer,
+            long commonPropertiesMarked, UIComponent component) throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONFOCUS_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONFOCUS_ATTR, HTML.ONFOCUS_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONBLUR_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONBLUR_ATTR, HTML.ONBLUR_ATTR);
+        }
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONSELECT_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONSELECT_ATTR, HTML.ONSELECT_ATTR);
+        }
+    }
+    
+    public static final void renderChangeEventProperty(ResponseWriter writer,
+            long commonPropertiesMarked, UIComponent component) throws IOException
+    {
+        if ((commonPropertiesMarked & CommonPropertyConstants.ONCHANGE_PROP) != 0)
+        {
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
+                    HTML.ONCHANGE_ATTR, HTML.ONCHANGE_ATTR);
+        }
+    }
+    
     public static void renderAccesskeyTabindexProperties(ResponseWriter writer,
             long commonPropertiesMarked, UIComponent component)
             throws IOException
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ACCESSKEY_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ACCESSKEY_ATTR, HTML.ACCESSKEY_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.TABINDEX_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.TABINDEX_ATTR, HTML.TABINDEX_ATTR);
         }
     }
@@ -223,12 +259,12 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ALIGN_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ALIGN_ATTR, HTML.ALIGN_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ALT_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ALT_ATTR, HTML.ALT_ATTR);
         }
     }
@@ -244,7 +280,7 @@ public final class CommonPropertyUtils
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.ALT_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ALT_ATTR, HTML.ALT_ATTR);
         }
         if ((commonPropertiesMarked & CommonPropertyConstants.CHECKED_PROP) != 0)
@@ -276,42 +312,42 @@ public final class CommonPropertyUtils
         renderAccesskeyTabindexProperties(writer, commonPropertiesMarked, component);
         if ((commonPropertiesMarked & CommonPropertyConstants.CHARSET_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.CHARSET_ATTR, HTML.CHARSET_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.COORDS_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.COORDS_ATTR, HTML.COORDS_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.HREFLANG_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.HREFLANG_ATTR, HTML.HREFLANG_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.REL_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.REL_ATTR, HTML.REL_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.REV_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.REV_ATTR, HTML.REV_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.SHAPE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.SHAPE_ATTR, HTML.SHAPE_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.TARGET_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.TARGET_ATTR, HTML.TARGET_ATTR);
         }        
         if ((commonPropertiesMarked & CommonPropertyConstants.TYPE_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.TYPE_ATTR, HTML.TYPE_ATTR);
         }        
     }
@@ -438,7 +474,7 @@ public final class CommonPropertyUtils
         renderFocusBlurEventProperties(writer, commonPropertiesMarked, component);
         if ((commonPropertiesMarked & CommonPropertyConstants.ACCESSKEY_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ACCESSKEY_ATTR, HTML.ACCESSKEY_ATTR);
         }
     }
@@ -458,9 +494,23 @@ public final class CommonPropertyUtils
     {
         if ((commonPropertiesMarked & CommonPropertyConstants.ACCESSKEY_PROP) != 0)
         {
-            renderHTMLStringAttribute(writer, component,
+            HtmlRendererUtils.renderHTMLStringAttribute(writer, component,
                     HTML.ACCESSKEY_ATTR, HTML.ACCESSKEY_ATTR);
         }
         renderCommonPassthroughPropertiesWithoutEvents(writer, commonPropertiesMarked, component);
     }
+    
+    public static final void renderSelectPassthroughPropertiesWithoutDisabled(ResponseWriter writer,
+            long commonPropertiesMarked, UIComponent component)
+            throws IOException
+    {
+        renderCommonFieldPassthroughPropertiesWithoutDisabled(writer, commonPropertiesMarked, component);
+    }
+    
+    public static final void renderSelectPassthroughPropertiesWithoutDisabledAndEvents(ResponseWriter writer,
+            long commonPropertiesMarked, UIComponent component)
+            throws IOException
+    {
+        renderCommonFieldPassthroughPropertiesWithoutDisabledAndEvents(writer, commonPropertiesMarked, component);
+    }
 }

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlBodyRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlBodyRendererBase.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/HtmlBodyRendererBase.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlBodyRendererBase.java Thu Feb  2 20:00:42 2012
@@ -80,7 +80,24 @@ public class HtmlBodyRendererBase extend
             {
                 HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
             }
-            HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors);
+            if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
+            {
+                CommonPropertyUtils.renderEventProperties(writer, 
+                        CommonPropertyUtils.getCommonPropertiesMarked(component), component);
+            }
+            else
+            {
+                if (isCommonEventsOptimizationEnabled(facesContext))
+                {
+                    CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
+                           CommonPropertyUtils.getCommonPropertiesMarked(component),
+                           CommonEventUtils.getCommonEventsMarked(component), component, behaviors);
+                }
+                else
+                {
+                    HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors);
+                }
+            }
             HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONLOAD_ATTR, component,
                     ClientBehaviorEvents.LOAD, behaviors, HTML.ONLOAD_ATTR);
             HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONUNLOAD_ATTR, component,
@@ -125,10 +142,18 @@ public class HtmlBodyRendererBase extend
 
         ResponseWriter writer = facesContext.getResponseWriter();
         UIViewRoot root = facesContext.getViewRoot();
-        for (UIComponent child : root.getComponentResources(facesContext,
-                HTML.BODY_TARGET))
+        // Perf: use indexes for iteration over children,
+        // componentResources are javax.faces.component._ComponentChildrenList._ComponentChildrenList(UIComponent)  
+        List<UIComponent> componentResources = root.getComponentResources(facesContext,
+                HTML.BODY_TARGET);
+        int childrenCount = componentResources.size();
+        if (childrenCount > 0)
         {
-            child.encodeAll(facesContext);
+            for (int i = 0; i < childrenCount; i++)
+            {
+                UIComponent child = componentResources.get(i);
+                child.encodeAll(facesContext);
+            }
         }
         
         // render all unhandled FacesMessages when ProjectStage is Development

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.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/HtmlButtonRendererBase.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlButtonRendererBase.java Thu Feb  2 20:00:42 2012
@@ -229,7 +229,7 @@ public class HtmlButtonRendererBase
             //fallback into the pre 2.0 code to keep backwards compatibility with libraries which rely on internals
             if (!reset && !button)
             {
-                StringBuffer onClick = buildOnClick(uiComponent, facesContext, writer, validParams);
+                StringBuilder onClick = buildOnClick(uiComponent, facesContext, writer, validParams);
                 if (onClick.length() != 0)
                 {
                     writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
@@ -237,7 +237,7 @@ public class HtmlButtonRendererBase
             }
             else
             {
-                HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent, HTML.ONCLICK_ATTR, HTML.ONCLICK_ATTR);
+                HtmlRendererUtils.renderHTMLStringAttribute(writer, uiComponent, HTML.ONCLICK_ATTR, HTML.ONCLICK_ATTR);
             }
         }
         
@@ -345,7 +345,7 @@ public class HtmlButtonRendererBase
             userOnClick.append(';');
         }
 
-        StringBuffer rendererOnClick = new StringBuffer();
+        StringBuilder rendererOnClick = new StringBuilder();
 
         if (nestedFormInfo != null) 
         {
@@ -392,7 +392,7 @@ public class HtmlButtonRendererBase
         UIComponent nestingForm = formInfo.getForm();
         String formName = formInfo.getFormName();
 
-        StringBuffer onClick = new StringBuffer();
+        StringBuilder onClick = new StringBuilder();
 
         if (RendererUtils.isAdfOrTrinidadForm(formInfo.getForm()))
         {
@@ -404,7 +404,7 @@ public class HtmlButtonRendererBase
         }
         else
         {
-            StringBuffer params = addChildParameters(facesContext, component, nestingForm, validParams);
+            StringBuilder params = addChildParameters(facesContext, component, nestingForm, validParams);
 
             String target = getTarget(component);
 
@@ -440,11 +440,11 @@ public class HtmlButtonRendererBase
         return onClick.toString();
     }
     
-    private StringBuffer addChildParameters(FacesContext context, UIComponent component, 
+    private StringBuilder addChildParameters(FacesContext context, UIComponent component, 
             UIComponent nestingForm, List<UIParameter> validParams)
     {
         //add child parameters
-        StringBuffer params = new StringBuffer();
+        StringBuilder params = new StringBuilder();
         params.append("[");
         
         for (UIParameter param : validParams) 
@@ -473,7 +473,7 @@ public class HtmlButtonRendererBase
             if (value != null)
             {
                 strParamValue = value.toString();
-                StringBuffer buff = null;
+                StringBuilder buff = null;
                 for (int i = 0; i < strParamValue.length(); i++)
                 {
                     char c = strParamValue.charAt(i); 
@@ -481,7 +481,7 @@ public class HtmlButtonRendererBase
                     {
                         if (buff == null)
                         {
-                            buff = new StringBuffer();
+                            buff = new StringBuilder();
                             buff.append(strParamValue.substring(0,i));
                         }
                         buff.append('\\');
@@ -528,7 +528,7 @@ public class HtmlButtonRendererBase
         return target;
     }
 
-    protected StringBuffer buildOnClick(UIComponent uiComponent, FacesContext facesContext,
+    protected StringBuilder buildOnClick(UIComponent uiComponent, FacesContext facesContext,
                                         ResponseWriter writer, List<UIParameter> validParams)
         throws IOException
     {
@@ -559,7 +559,7 @@ public class HtmlButtonRendererBase
             DummyFormUtils.setWriteDummyForm(facesContext, true);
         }
         */
-        StringBuffer onClick = new StringBuffer();
+        StringBuilder onClick = new StringBuilder();
         String commandOnClick = (String) uiComponent.getAttributes().get(HTML.ONCLICK_ATTR);
 
         if (commandOnClick != null)
@@ -579,7 +579,7 @@ public class HtmlButtonRendererBase
             
             if (validParams != null && !validParams.isEmpty() )
             {
-                StringBuffer params = addChildParameters(
+                StringBuilder params = addChildParameters(
                         facesContext, uiComponent, nestedFormInfo.getForm(), validParams);
 
                 String target = getTarget(uiComponent);

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.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/HtmlCheckboxRendererBase.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java Thu Feb  2 20:00:42 2012
@@ -50,7 +50,8 @@ import org.apache.myfaces.shared.renderk
  * @author Anton Koinov
  * @version $Revision$ $Date$
  */
-public class HtmlCheckboxRendererBase extends HtmlRenderer {
+public class HtmlCheckboxRendererBase extends HtmlRenderer
+{
     //private static final Log log = LogFactory
     //        .getLog(HtmlCheckboxRendererBase.class);
     private static final Logger log = Logger.getLogger(HtmlCheckboxRendererBase.class.getName());
@@ -62,7 +63,8 @@ public class HtmlCheckboxRendererBase ex
     private static final String EXTERNAL_TRUE_VALUE = "true";
 
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
-            throws IOException {
+            throws IOException
+    {
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
         
         Map<String, List<ClientBehavior>> behaviors = null;
@@ -75,29 +77,42 @@ public class HtmlCheckboxRendererBase ex
             }
         }
         
-        if (uiComponent instanceof UISelectBoolean) {
+        if (uiComponent instanceof UISelectBoolean)
+        {
             Boolean value = org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanValue( uiComponent );
             boolean isChecked = value != null ? value.booleanValue() : false;
-            renderCheckbox(facesContext, uiComponent, EXTERNAL_TRUE_VALUE, false,isChecked, true, null); //TODO: the selectBoolean is never disabled
-        } else if (uiComponent instanceof UISelectMany) {
+            renderCheckbox(facesContext, uiComponent, EXTERNAL_TRUE_VALUE, false,isChecked, true, null); 
+                //TODO: the selectBoolean is never disabled
+        }
+        else if (uiComponent instanceof UISelectMany)
+        {
             renderCheckboxList(facesContext, (UISelectMany) uiComponent);
-        } else {
+        }
+        else
+        {
             throw new IllegalArgumentException("Unsupported component class "
                     + uiComponent.getClass().getName());
         }
     }
 
     public void renderCheckboxList(FacesContext facesContext,
-            UISelectMany selectMany) throws IOException {
+            UISelectMany selectMany) throws IOException
+    {
 
         String layout = getLayout(selectMany);
         boolean pageDirectionLayout = false; //Default to lineDirection
-        if (layout != null) {
-            if (layout.equals(PAGE_DIRECTION)) {
+        if (layout != null)
+        {
+            if (layout.equals(PAGE_DIRECTION))
+            {
                 pageDirectionLayout = true;
-            } else if (layout.equals(LINE_DIRECTION)) {
+            } 
+            else if (layout.equals(LINE_DIRECTION))
+            {
                 pageDirectionLayout = false;
-            } else {
+            }
+            else
+            {
                 log.severe("Wrong layout attribute for component "
                         + selectMany.getClientId(facesContext) + ": " + layout);
             }
@@ -125,21 +140,28 @@ public class HtmlCheckboxRendererBase ex
         }        
 
         if (!pageDirectionLayout)
+        {
             writer.startElement(HTML.TR_ELEM, selectMany);
+        }
         
         Converter converter = getConverter(facesContext, selectMany);
 
-        Set lookupSet = org.apache.myfaces.shared.renderkit.RendererUtils.getSubmittedValuesAsSet(facesContext, selectMany, converter, selectMany);
+        Set lookupSet = org.apache.myfaces.shared.renderkit.RendererUtils.getSubmittedValuesAsSet(
+                facesContext, selectMany, converter, selectMany);
         boolean useSubmittedValues = lookupSet != null;
 
-        if (!useSubmittedValues) {
-            lookupSet = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectedValuesAsSet(facesContext, selectMany, converter, selectMany);
+        if (!useSubmittedValues)
+        {
+            lookupSet = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectedValuesAsSet(
+                    facesContext, selectMany, converter, selectMany);
         }
 
         int itemNum = 0;
 
-        for (Iterator it = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectItemList(selectMany, facesContext)
-                .iterator(); it.hasNext();) {
+        for (Iterator it = org.apache.myfaces.shared.renderkit.RendererUtils.getSelectItemList(
+                selectMany, facesContext)
+                .iterator(); it.hasNext();)
+        {
             SelectItem selectItem = (SelectItem) it.next();
             
             itemNum = renderGroupOrItemCheckbox(facesContext, selectMany, 
@@ -148,12 +170,16 @@ public class HtmlCheckboxRendererBase ex
         }
 
         if (!pageDirectionLayout)
+        {
             writer.endElement(HTML.TR_ELEM);
+        }
         writer.endElement(HTML.TABLE_ELEM);
     }
 
-    protected String getLayout(UISelectMany selectMany) {
-        if (selectMany instanceof HtmlSelectManyCheckbox) {
+    protected String getLayout(UISelectMany selectMany)
+    {
+        if (selectMany instanceof HtmlSelectManyCheckbox)
+        {
             return ((HtmlSelectManyCheckbox) selectMany).getLayout();
         } 
         
@@ -176,7 +202,8 @@ public class HtmlCheckboxRendererBase ex
     protected int renderGroupOrItemCheckbox(FacesContext facesContext,
                                              UIComponent uiComponent, SelectItem selectItem,
                                              boolean useSubmittedValues, Set lookupSet,
-                                             Converter converter, boolean pageDirectionLayout, Integer itemNum) throws IOException
+                                             Converter converter, boolean pageDirectionLayout, 
+                                             Integer itemNum) throws IOException
     {
 
         ResponseWriter writer = facesContext.getResponseWriter();
@@ -188,7 +215,9 @@ public class HtmlCheckboxRendererBase ex
         if (isSelectItemGroup)
         {
             if (pageDirectionLayout)
+            {
                 writer.startElement(HTML.TR_ELEM, selectMany);
+            }
 
             writer.startElement(HTML.TD_ELEM, selectMany);
             writer.write(selectItem.getLabel());
@@ -205,7 +234,9 @@ public class HtmlCheckboxRendererBase ex
             writer.writeAttribute(HTML.BORDER_ATTR, "0", null);
             
             if(!pageDirectionLayout)
+            {
                 writer.startElement(HTML.TR_ELEM, selectMany);
+            }
 
             SelectItemGroup group = (SelectItemGroup) selectItem;
             SelectItem[] selectItems = group.getSelectItems();
@@ -217,18 +248,24 @@ public class HtmlCheckboxRendererBase ex
             }
 
             if(!pageDirectionLayout)
+            {
                 writer.endElement(HTML.TR_ELEM);
+            }
             writer.endElement(HTML.TABLE_ELEM);
             writer.endElement(HTML.TD_ELEM);
 
             if (pageDirectionLayout)
+            {
                 writer.endElement(HTML.TR_ELEM);
+            }
 
         }
         else
         {
-            Object itemValue = selectItem.getValue(); // TODO : Check here for getSubmittedValue. Look at RendererUtils.getValue
-            String itemStrValue = org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedStringValue(facesContext, selectMany, converter, itemValue);
+            Object itemValue = selectItem.getValue(); // TODO : Check here for getSubmittedValue. 
+                                                      // Look at RendererUtils.getValue
+            String itemStrValue = org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedStringValue(
+                    facesContext, selectMany, converter, itemValue);
             
             boolean checked = lookupSet.contains(itemStrValue);
             
@@ -245,7 +282,9 @@ public class HtmlCheckboxRendererBase ex
 
             writer.write("\t\t");
             if (pageDirectionLayout)
+            {
                 writer.startElement(HTML.TR_ELEM, selectMany);
+            }
             writer.startElement(HTML.TD_ELEM, selectMany);
 
             boolean disabled = selectItem.isDisabled();
@@ -260,7 +299,9 @@ public class HtmlCheckboxRendererBase ex
 
             writer.endElement(HTML.TD_ELEM);
             if (pageDirectionLayout)
+            {
                 writer.endElement(HTML.TR_ELEM);
+            }
             
             // we rendered one checkbox --> increment itemNum
             itemNum++;
@@ -272,7 +313,8 @@ public class HtmlCheckboxRendererBase ex
     @Deprecated
     protected void renderCheckbox(FacesContext facesContext,
             UIComponent uiComponent, String value, String label,
-            boolean disabled, boolean checked, boolean renderId) throws IOException {
+            boolean disabled, boolean checked, boolean renderId) throws IOException
+    {
         renderCheckbox(facesContext, uiComponent, value, disabled, checked, renderId, 0);
     }
 
@@ -281,10 +323,13 @@ public class HtmlCheckboxRendererBase ex
      * @return the 'id' value of the rendered element
      */
     protected String renderCheckbox(FacesContext facesContext,
-            UIComponent uiComponent, String value, boolean disabled, boolean checked, boolean renderId, Integer itemNum) throws IOException {
+            UIComponent uiComponent, String value, boolean disabled, boolean checked, 
+            boolean renderId, Integer itemNum) throws IOException
+    {
         String clientId = uiComponent.getClientId(facesContext);
 
-        String itemId = (itemNum == null)? null : clientId + UINamingContainer.getSeparatorChar(facesContext) + itemNum;
+        String itemId = (itemNum == null)? null : clientId + 
+                UINamingContainer.getSeparatorChar(facesContext) + itemNum;
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
@@ -301,29 +346,63 @@ public class HtmlCheckboxRendererBase ex
         writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_CHECKBOX, null);
         writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
         
-        if (checked) {
-            writer.writeAttribute(HTML.CHECKED_ATTR, org.apache.myfaces.shared.renderkit.html.HTML.CHECKED_ATTR, null);
+        if (checked)
+        {
+            writer.writeAttribute(HTML.CHECKED_ATTR, 
+                    org.apache.myfaces.shared.renderkit.html.HTML.CHECKED_ATTR, null);
         }
         
-        if (disabled) {
+        if (disabled)
+        {
             writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
         }
 
-        if ((value != null) && (value.length() > 0)) {
+        if ((value != null) && (value.length() > 0))
+        {
             writer.writeAttribute(HTML.VALUE_ATTR, value, null);
         }
 
         Map<String, List<ClientBehavior>> behaviors = null;
         if (uiComponent instanceof UISelectBoolean)
         {
-            if (uiComponent instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext()))
+            if (uiComponent instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(
+                    facesContext.getExternalContext()))
             {
                 behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
                 
-                HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
+                if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
+                {
+                    long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
+                    CommonPropertyUtils.renderChangeEventProperty(writer, 
+                            commonPropertiesMarked, uiComponent);
+                    CommonPropertyUtils.renderEventProperties(writer, 
+                            commonPropertiesMarked, uiComponent);
+                    CommonPropertyUtils.renderFieldEventPropertiesWithoutOnchange(writer, 
+                            commonPropertiesMarked, uiComponent);
+                }
+                else
+                {
+                    long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
+                    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);
+                    }
+                }
+                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
+                        HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
             }
             else
             {
@@ -333,14 +412,45 @@ public class HtmlCheckboxRendererBase ex
         }
         else
         {
-            if (uiComponent instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext()))
+            if (uiComponent instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(
+                    facesContext.getExternalContext()))
             {
                 behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
                 
-                HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, behaviors);
-                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE_AND_EVENTS);
+                if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
+                {
+                    long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
+                    CommonPropertyUtils.renderChangeEventProperty(writer, 
+                            commonPropertiesMarked, uiComponent);
+                    CommonPropertyUtils.renderEventProperties(writer, 
+                            commonPropertiesMarked, uiComponent);
+                    CommonPropertyUtils.renderFieldEventPropertiesWithoutOnchange(writer, 
+                            commonPropertiesMarked, uiComponent);
+                }
+                else
+                {
+                    long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent);
+                    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);
+                    }
+                }
+                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, 
+                        HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE_AND_EVENTS);
             }
             else
             {
@@ -348,7 +458,8 @@ public class HtmlCheckboxRendererBase ex
                         HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE);
             }
         }
-        if (isDisabled(facesContext, uiComponent)) {
+        if (isDisabled(facesContext, uiComponent))
+        {
             writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
         }
         
@@ -358,26 +469,38 @@ public class HtmlCheckboxRendererBase ex
     }
 
     protected boolean isDisabled(FacesContext facesContext,
-            UIComponent component) {
+            UIComponent component)
+    {
         //TODO: overwrite in extended HtmlCheckboxRenderer and check for
         // enabledOnUserRole
-        if (component instanceof HtmlSelectBooleanCheckbox) {
+        if (component instanceof HtmlSelectBooleanCheckbox)
+        {
             return ((HtmlSelectBooleanCheckbox) component).isDisabled();
-        } else if (component instanceof HtmlSelectManyCheckbox) {
+        }
+        else if (component instanceof HtmlSelectManyCheckbox)
+        {
             return ((HtmlSelectManyCheckbox) component).isDisabled();
-        } else {
+        }
+        else
+        {
             return org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(component,
                     HTML.DISABLED_ATTR, false);
         }
     }
 
-    public void decode(FacesContext facesContext, UIComponent component) {
+    public void decode(FacesContext facesContext, UIComponent component)
+    {
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, component, null);
-        if (component instanceof UISelectBoolean) {
+        if (component instanceof UISelectBoolean)
+        {
             HtmlRendererUtils.decodeUISelectBoolean(facesContext, component);
-        } else if (component instanceof UISelectMany) {
+        }
+        else if (component instanceof UISelectMany)
+        {
             HtmlRendererUtils.decodeUISelectMany(facesContext, component);
-        } else {
+        }
+        else
+        {
             throw new IllegalArgumentException("Unsupported component class "
                     + component.getClass().getName());
         }
@@ -390,14 +513,20 @@ public class HtmlCheckboxRendererBase ex
 
     public Object getConvertedValue(FacesContext facesContext,
             UIComponent component, Object submittedValue)
-            throws ConverterException {
+            throws ConverterException
+    {
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, component, null);
-        if (component instanceof UISelectBoolean) {
+        if (component instanceof UISelectBoolean)
+        {
             return submittedValue;
-        } else if (component instanceof UISelectMany) {
+        }
+        else if (component instanceof UISelectMany)
+        {
             return org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUISelectManyValue(facesContext,
                     (UISelectMany) component, submittedValue);
-        } else {
+        }
+        else
+        {
             throw new IllegalArgumentException("Unsupported component class "
                     + component.getClass().getName());
         }

Modified: myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlFormRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlFormRendererBase.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/HtmlFormRendererBase.java (original)
+++ myfaces/shared/trunk_4.0.x/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlFormRendererBase.java Thu Feb  2 20:00:42 2012
@@ -84,7 +84,8 @@ public class HtmlFormRendererBase
         writer.writeAttribute(HTML.ID_ATTR, clientId, null);
         writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
         writer.writeAttribute(HTML.METHOD_ATTR, method, null);
-        if (acceptCharset != null) {
+        if (acceptCharset != null)
+        {
             writer.writeAttribute(HTML.ACCEPT_CHARSET_ATTR, acceptCharset, null);
         }
         String encodedActionURL = facesContext.getExternalContext().encodeActionURL(actionURL);
@@ -93,10 +94,28 @@ public class HtmlFormRendererBase
                 encodedActionURL,
                 null);
         
-        if (htmlForm instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext()))
+        if (htmlForm instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(
+                facesContext.getExternalContext()))
         {
             behaviors = ((ClientBehaviorHolder) htmlForm).getClientBehaviors();
-            HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, htmlForm, behaviors);
+            if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
+            {
+                CommonPropertyUtils.renderEventProperties(writer, 
+                        CommonPropertyUtils.getCommonPropertiesMarked(htmlForm), htmlForm);
+            }
+            else
+            {
+                if (isCommonEventsOptimizationEnabled(facesContext))
+                {
+                    CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
+                           CommonPropertyUtils.getCommonPropertiesMarked(htmlForm),
+                           CommonEventUtils.getCommonEventsMarked(htmlForm), htmlForm, behaviors);
+                }
+                else
+                {
+                    HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, htmlForm, behaviors);
+                }
+            }
             if (isCommonPropertiesOptimizationEnabled(facesContext))
             {
                 CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, 
@@ -105,7 +124,8 @@ public class HtmlFormRendererBase
             }
             else
             {
-                HtmlRendererUtils.renderHTMLAttributes(writer, htmlForm, HTML.FORM_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
+                HtmlRendererUtils.renderHTMLAttributes(writer, htmlForm, 
+                        HTML.FORM_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
             }
         }
         else
@@ -139,15 +159,18 @@ public class HtmlFormRendererBase
         afterFormElementsStart(facesContext, component);
     }
 
-    protected String getActionUrl(FacesContext facesContext, UIForm form) {
+    protected String getActionUrl(FacesContext facesContext, UIForm form)
+    {
         return getActionUrl(facesContext);
     }
 
-    protected String getMethod(FacesContext facesContext, UIForm form) {
+    protected String getMethod(FacesContext facesContext, UIForm form)
+    {
         return "post";
     }
 
-    protected String getAcceptCharset(FacesContext facesContext, UIForm form ) {
+    protected String getAcceptCharset(FacesContext facesContext, UIForm form )
+    {
         return (String)form.getAttributes().get( JSFAttr.ACCEPTCHARSET_ATTR );
     }
 
@@ -198,25 +221,30 @@ public class HtmlFormRendererBase
 
         afterFormElementsEnd(facesContext, component);
         
-        for (UIComponent child : facesContext.getViewRoot().getComponentResources(facesContext,
-            FORM_TARGET))
+        List<UIComponent> componentResources = facesContext.getViewRoot().getComponentResources(facesContext,
+            FORM_TARGET);
+        
+        for (int i = 0, size = componentResources.size(); i < size; i++)
         {
+           UIComponent child = componentResources.get(i);
            child.encodeAll (facesContext);
         }
         
         writer.endElement(HTML.FORM_ELEM);
     }
 
-    private static String getHiddenCommandInputsSetName(FacesContext facesContext, UIComponent form) {
-        StringBuffer buf = new StringBuffer();
+    private static String getHiddenCommandInputsSetName(FacesContext facesContext, UIComponent form)
+    {
+        StringBuilder buf = new StringBuilder(HIDDEN_COMMAND_INPUTS_SET_ATTR.length()+20);
         buf.append(HIDDEN_COMMAND_INPUTS_SET_ATTR);
         buf.append("_");
         buf.append(form.getClientId(facesContext));
         return buf.toString();
     }
 
-    private static String getScrollHiddenInputName(FacesContext facesContext, UIComponent form) {
-        StringBuffer buf = new StringBuffer();
+    private static String getScrollHiddenInputName(FacesContext facesContext, UIComponent form)
+    {
+        StringBuilder buf = new StringBuilder(SCROLL_HIDDEN_INPUT.length()+20);
         buf.append(SCROLL_HIDDEN_INPUT);
         buf.append("_");
         buf.append(form.getClientId(facesContext));
@@ -255,27 +283,35 @@ public class HtmlFormRendererBase
 
     public static void addHiddenCommandParameter(FacesContext facesContext, UIComponent form, String paramName)
     {
-        Set set = (Set) facesContext.getExternalContext().getRequestMap().get(getHiddenCommandInputsSetName(facesContext, form));
+        Set set = (Set) facesContext.getExternalContext().getRequestMap().get(
+                getHiddenCommandInputsSetName(facesContext, form));
         if (set == null)
         {
             set = new HashSet();
-            facesContext.getExternalContext().getRequestMap().put(getHiddenCommandInputsSetName(facesContext, form), set);
+            facesContext.getExternalContext().getRequestMap().put(
+                    getHiddenCommandInputsSetName(facesContext, form), set);
         }
         set.add(paramName);
     }
 
-    public static void renderScrollHiddenInputIfNecessary(UIComponent form, FacesContext facesContext, ResponseWriter writer)
-        throws IOException {
-        if (form == null) {
+    public static void renderScrollHiddenInputIfNecessary(
+            UIComponent form, FacesContext facesContext, ResponseWriter writer)
+        throws IOException
+    {
+        if (form == null)
+        {
             return;
         }
 
-        if (facesContext.getExternalContext().getRequestMap().get(getScrollHiddenInputName(facesContext, form)) == null)
+        if (facesContext.getExternalContext().getRequestMap().get(
+                getScrollHiddenInputName(facesContext, form)) == null)
         {
-            if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll()) {
+            if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll())
+            {
                 HtmlRendererUtils.renderAutoScrollHiddenInput(facesContext, writer);
             }
-            facesContext.getExternalContext().getRequestMap().put(getScrollHiddenInputName(facesContext, form), Boolean.TRUE);
+            facesContext.getExternalContext().getRequestMap().put(getScrollHiddenInputName(
+                    facesContext, form), Boolean.TRUE);
         }
     }
 
@@ -294,7 +330,9 @@ public class HtmlFormRendererBase
      */
     protected void beforeFormElementsStart(FacesContext facesContext, UIComponent component)
             throws IOException
-    {}
+    {
+        
+    }
 
     /**
      * Called after the state and any elements are added to the form tag in the
@@ -302,7 +340,9 @@ public class HtmlFormRendererBase
      */
     protected void afterFormElementsStart(FacesContext facesContext, UIComponent component)
             throws IOException
-    {}
+    {
+        
+    }
 
     /**
      * Called before the state and any elements are added to the form tag in the
@@ -310,7 +350,9 @@ public class HtmlFormRendererBase
      */
     protected void beforeFormElementsEnd(FacesContext facesContext, UIComponent component)
             throws IOException
-    {}
+    {
+        
+    }
 
     /**
      * Called after the state and any elements are added to the form tag in the
@@ -318,5 +360,7 @@ public class HtmlFormRendererBase
      */
     protected void afterFormElementsEnd(FacesContext facesContext, UIComponent component)
             throws IOException
-    {}
+    {
+        
+    }
 }



Mime
View raw message