myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1468656 [2/7] - in /myfaces: core/trunk/ core/trunk/api/ core/trunk/assembly/ core/trunk/bundle/ core/trunk/impl/ core/trunk/parent/ core/trunk/shared-public/ core/trunk/shared/ current22/ current22/client-window-example/ shared/trunk/ sha...
Date Tue, 16 Apr 2013 22:49:47 GMT
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlJavaScriptUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlJavaScriptUtils.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlJavaScriptUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlJavaScriptUtils.java Tue Apr 16 22:49:45 2013
@@ -1,756 +1,756 @@
-/*
- * 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.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
-
-import javax.faces.component.UINamingContainer;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-import org.apache.myfaces.shared.config.MyfacesConfig;
-import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils.ScriptContext;
-import org.apache.myfaces.shared.renderkit.html.util.JavascriptUtils;
-import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
-
-public final class HtmlJavaScriptUtils
-{
-    private static final Logger log = Logger.getLogger(HtmlJavaScriptUtils.class
-            .getName());
-
-    private static final String AUTO_SCROLL_PARAM = "autoScroll";
-    private static final String AUTO_SCROLL_FUNCTION = "getScrolling";
-
-    private static final String SET_HIDDEN_INPUT_FN_NAME = "oamSetHiddenInput";
-    private static final String SET_HIDDEN_INPUT_FN_NAME_JSF2 = "myfaces.oam.setHiddenInput";
-
-    private static final String FIRST_SUBMIT_SCRIPT_ON_PAGE = "org.apache.MyFaces.FIRST_SUBMIT_SCRIPT_ON_PAGE";
-    private static final String CLEAR_HIDDEN_INPUT_FN_NAME = "oamClearHiddenInput";
-    
-
-    @SuppressWarnings("unchecked")
-    public static void renderFormSubmitScript(FacesContext facesContext)
-            throws IOException
-    {
-
-        Map map = facesContext.getExternalContext().getRequestMap();
-        Boolean firstScript = (Boolean) map.get(FIRST_SUBMIT_SCRIPT_ON_PAGE);
-
-        if (firstScript == null || firstScript.equals(Boolean.TRUE))
-        {
-            map.put(FIRST_SUBMIT_SCRIPT_ON_PAGE, Boolean.FALSE);
-            renderFormSubmitScriptIfNecessary(facesContext);
-
-            //we have to render the config just in case
-            renderConfigOptionsIfNecessary(facesContext);
-        }
-    }
-    
-    /**
-     * @param facesContext
-     * @throws IOException
-     */
-    private static void renderFormSubmitScriptIfNecessary(
-            FacesContext facesContext) throws IOException
-    {
-        final ExternalContext externalContext = facesContext
-                .getExternalContext();
-        final MyfacesConfig currentInstance = MyfacesConfig
-                .getCurrentInstance(externalContext);
-        ResponseWriter writer = facesContext.getResponseWriter();
-
-        if (currentInstance.isRenderFormSubmitScriptInline())
-        {
-            writer.startElement(HTML.SCRIPT_ELEM, null);
-            writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
-
-            boolean autoScroll = currentInstance.isAutoScroll();
-
-            ScriptContext context = new ScriptContext(
-                    currentInstance.isPrettyHtml());
-            context.prettyLine();
-            context.increaseIndent();
-
-            prepareScript(facesContext, context, autoScroll);
-
-            writer.writeText(context.toString(), null);
-
-            writer.endElement(HTML.SCRIPT_ELEM);
-        }
-        else
-        {
-            ResourceUtils
-                    .renderMyfacesJSInlineIfNecessary(facesContext, writer);
-        }
-    }
-    
-    private static void renderConfigOptionsIfNecessary(FacesContext facesContext)
-            throws IOException
-    {
-        ResponseWriter writer = facesContext.getResponseWriter();
-        MyfacesConfig config = MyfacesConfig.getCurrentInstance(facesContext
-                .getExternalContext());
-        ScriptContext script = new ScriptContext(config.isPrettyHtml());
-        boolean autoScroll = config.isAutoScroll();
-        boolean autoSave = JavascriptUtils.isSaveFormSubmitLinkIE(facesContext
-                .getExternalContext());
-
-        if (autoScroll || autoSave)
-        {
-            script.prettyLine();
-            script.increaseIndent();
-            script.append("(!window.myfaces) ? window.myfaces = {} : null;");
-            script.append("(!myfaces.core) ? myfaces.core = {} : null;");
-            script.append("(!myfaces.core.config) ? myfaces.core.config = {} : null;");
-        }
-
-        if (autoScroll)
-        {
-            script.append("myfaces.core.config.autoScroll = true;");
-        }
-        if (autoSave)
-        {
-            script.append("myfaces.core.config.ieAutoSave = true;");
-        }
-        if (autoScroll || autoSave)
-        {
-            writer.startElement(HTML.SCRIPT_ELEM, null);
-            writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
-            writer.writeText(script.toString(), null);
-            writer.endElement(HTML.SCRIPT_ELEM);
-        }
-    }
-    /**
-     * @param facesContext
-     * @param context
-     * @param autoScroll
-     */
-    private static void prepareScript(FacesContext facesContext,
-            ScriptContext context, boolean autoScroll)
-    {
-
-        final char separatorChar = UINamingContainer
-                .getSeparatorChar(facesContext);
-        context.prettyLine();
-
-        //render a function to create a hidden input, if it doesn't exist
-        context.append("function ");
-        context.append(SET_HIDDEN_INPUT_FN_NAME).append(
-                "(formname, name, value)");
-        context.append("{");
-        context.append("var form = document.forms[formname];");
-        context.prettyLine();
-        context.append("if (typeof form == 'undefined')");
-        context.append("{");
-        context.append("form = document.getElementById(formname);");
-        context.append("}");
-        context.prettyLine();
-        context.append("if(typeof form.elements[name]!='undefined' && "+
-                "(form.elements[name].nodeName=='INPUT' || form.elements[name].nodeName=='input'))");
-        context.append("{");
-        context.append("form.elements[name].value=value;");
-        context.append("}");
-        context.append("else");
-        context.append("{");
-        context.append("var newInput = document.createElement('input');");
-        context.prettyLine();
-        context.append("newInput.setAttribute('type','hidden');");
-        context.prettyLine();
-        context.append("newInput.setAttribute('id',name);"); // IE hack; See MYFACES-1805
-        context.prettyLine();
-        context.append("newInput.setAttribute('name',name);");
-        context.prettyLine();
-        context.append("newInput.setAttribute('value',value);");
-        context.prettyLine();
-        context.append("form.appendChild(newInput);");
-        context.append("}");
-
-        context.append("}");
-
-        context.prettyLine();
-
-        context.prettyLine();
-
-        //render a function to clear a hidden input, if it exists        
-        context.append("function ");
-        context.append(CLEAR_HIDDEN_INPUT_FN_NAME).append(
-                "(formname, name, value)");
-        context.append("{");
-        context.append("var form = document.forms[formname];");
-        context.prettyLine();
-        context.append("if (typeof form == 'undefined')");
-        context.append("{");
-        context.append("form = document.getElementById(formname);");
-        context.append("}");
-        context.prettyLine();
-        context.append("var hInput = form.elements[name];");
-        context.prettyLine();
-        context.append("if(typeof hInput !='undefined')");
-        context.append("{");
-        //context.append("form.elements[name].value=null;");
-        context.append("form.removeChild(hInput);");
-        context.append("}");
-
-        context.append("}");
-
-        context.prettyLine();
-
-        context.append("function ");
-        context.append(HtmlRendererUtils.SUBMIT_FORM_FN_NAME).append(
-                "(formName, linkId, target, params)");
-        context.append("{");
-
-        //call the script to clear the form (clearFormHiddenParams_<formName>) method - 
-        //optionally, only necessary for IE5.5.
-        //todo: if IE5.5. is ever desupported, we can get rid of this and instead rely on 
-        //the last part of this script to
-        //clear the parameters
-        appendClearHiddenCommandFormParamsFunctionCall(
-                context, null);
-
-        if (autoScroll)
-        {
-            appendAutoScrollAssignment(facesContext, context, null);
-        }
-
-        context.prettyLine();
-
-        context.append("var form = document.forms[formName];");
-        context.prettyLine();
-        context.append("if (typeof form == 'undefined')");
-        context.append("{");
-        context.append("form = document.getElementById(formName);");
-        context.append("}");
-        context.prettyLine();
-
-        if (JavascriptUtils.isSaveFormSubmitLinkIE(FacesContext
-                .getCurrentInstance().getExternalContext()))
-        {
-            context.append("var agentString = navigator.userAgent.toLowerCase();");
-            context.prettyLine();
-            //context.append("var isIE = false;");
-            context.prettyLine();
-            context.append("if (agentString.indexOf('msie') != -1)");
-
-            context.append("{");
-            context.append("if (!(agentString.indexOf('ppc') != -1 &&"+
-                    " agentString.indexOf('windows ce') != -1 && version >= 4.0))");
-            context.append("{");
-            context.append("window.external.AutoCompleteSaveForm(form);");
-            //        context.append("isIE = false;");
-            context.append("}");
-            //        context.append("else");
-            //        context.append("{");
-            //        context.append("isIE = true;");
-            //        context.prettyLine();
-            //        context.append("}");
-
-            context.append("}");
-
-            context.prettyLine();
-        }
-        //set the target (and save it). This should be done always, 
-        //and the default value of target is always valid.
-        context.append("var oldTarget = form.target;");
-        context.prettyLine();
-        context.append("if(target != null)");
-        context.append("{");
-        context.prettyLine();
-        context.append("form.target=target;");
-        context.append("}");
-
-        //set the submit parameters
-
-        context.append("if((typeof params!='undefined') && params != null)");
-        context.append("{");
-        context.prettyLine();
-        context.append("for(var i=0, param; (param = params[i]); i++)");
-        context.append("{");
-        context.append(SET_HIDDEN_INPUT_FN_NAME).append(
-                "(formName,param[0], param[1]);");
-        context.append("}");
-        context.append("}");
-
-        context.prettyLine();
-
-        context.append(SET_HIDDEN_INPUT_FN_NAME);
-        context.append("(formName,formName +'" + separatorChar + "'+'"
-                + HtmlRendererUtils.HIDDEN_COMMANDLINK_FIELD_NAME
-                + "',linkId);");
-
-        context.prettyLine();
-        context.prettyLine();
-
-        //do the actual submit calls
-
-        context.append("if(form.onsubmit)");
-        context.append("{");
-        context.append("var result=form.onsubmit();");
-        context.prettyLine();
-        context.append("if((typeof result=='undefined')||result)");
-        context.append("{");
-        context.append("try");
-        context.append("{");
-        context.append("form.submit();");
-        context.append("}");
-        context.append("catch(e){}");
-        context.append("}");
-        context.append("}");
-        context.append("else ");
-        context.append("{");
-        context.append("try");
-        context.append("{");
-        context.append("form.submit();");
-        context.append("}");
-        context.append("catch(e){}");
-        context.append("}");
-
-        //reset the target
-        context.prettyLine();
-        //Restore the old target, no more questions asked
-        context.append("form.target=oldTarget;");
-        context.prettyLine();
-
-        //clear the individual parameters - to make sure that even if the clear-function isn't called,
-        // the back button/resubmit functionality will still work in all browsers except IE 5.5.
-
-        context.append("if((typeof params!='undefined') && params != null)");
-        context.append("{");
-        context.prettyLine();
-        context.append("for(var i=0, param; (param = params[i]); i++)");
-        context.append("{");
-        context.append(CLEAR_HIDDEN_INPUT_FN_NAME).append(
-                "(formName,param[0], param[1]);");
-        context.append("}");
-        context.append("}");
-
-        context.prettyLine();
-
-        context.append(CLEAR_HIDDEN_INPUT_FN_NAME);
-        context.append("(formName,formName +'" + separatorChar + "'+'"
-                + HtmlRendererUtils.HIDDEN_COMMANDLINK_FIELD_NAME
-                + "',linkId);");
-
-        //return false, so that browser does not handle the click
-        context.append("return false;");
-        context.append("}");
-
-        context.prettyLineDecreaseIndent();
-    }
-    
-    public static void appendAutoScrollAssignment(StringBuilder onClickValue,
-            String formName)
-    {
-        appendAutoScrollAssignment(FacesContext.getCurrentInstance(),
-                new ScriptContext(onClickValue, false), formName);
-    }
-
-    /**
-     * 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(FacesContext context,
-            StringBuilder onClickValue, String formName)
-    {
-        appendAutoScrollAssignment(context, new ScriptContext(onClickValue,
-                false), formName);
-    }
-    
-    private static void appendAutoScrollAssignment(FacesContext context,
-            ScriptContext scriptContext, String formName)
-    {
-        String formNameStr = formName == null ? "formName" : (new StringBuilder(
-                "'").append(formName).append("'").toString());
-        String paramName = new StringBuilder().append("'")
-                .append(AUTO_SCROLL_PARAM).append("'").toString();
-        String value = new StringBuilder().append(AUTO_SCROLL_FUNCTION)
-                .append("()").toString();
-
-        scriptContext.prettyLine();
-        scriptContext.append("if(typeof window." + AUTO_SCROLL_FUNCTION
-                + "!='undefined')");
-        scriptContext.append("{");
-        if (MyfacesConfig.getCurrentInstance(context.getExternalContext())
-                .isRenderFormSubmitScriptInline())
-        {
-            scriptContext.append(SET_HIDDEN_INPUT_FN_NAME);
-        }
-        else
-        {
-            scriptContext.append(SET_HIDDEN_INPUT_FN_NAME_JSF2);
-        }
-        scriptContext.append("(").append(formNameStr).append(",")
-                .append(paramName).append(",").append(value).append(");");
-        scriptContext.append("}");
-
-    }
-    
-    public static String getAutoScrollFunction(FacesContext facesContext)
-    {
-        ScriptContext script = new ScriptContext(MyfacesConfig
-                .getCurrentInstance(facesContext.getExternalContext())
-                .isPrettyHtml());
-
-        script.prettyLineIncreaseIndent();
-
-        script.append("function ");
-        script.append(AUTO_SCROLL_FUNCTION);
-        script.append("()");
-        script.append("{");
-        script.append("var x = 0; var y = 0;");
-        script.append("if (self.pageXOffset || self.pageYOffset)");
-        script.append("{");
-        script.append("x = self.pageXOffset;");
-        script.prettyLine();
-        script.append("y = self.pageYOffset;");
-        script.append("}");
-        script.append(" else if ((document.documentElement && document.documentElement.scrollLeft)||"+
-                "(document.documentElement && document.documentElement.scrollTop))");
-        script.append("{");
-        script.append("x = document.documentElement.scrollLeft;");
-        script.prettyLine();
-        script.append("y = document.documentElement.scrollTop;");
-        script.append("}");
-        script.append(" else if (document.body) ");
-        script.append("{");
-        script.append("x = document.body.scrollLeft;");
-        script.prettyLine();
-        script.append("y = document.body.scrollTop;");
-        script.append("}");
-        script.append("return x + \",\" + y;");
-        script.append("}");
-
-        ExternalContext externalContext = facesContext.getExternalContext();
-        String oldViewId = JavascriptUtils.getOldViewId(externalContext);
-        if (oldViewId != null
-                && oldViewId.equals(facesContext.getViewRoot().getViewId()))
-        {
-            //ok, we stayed on the same page, so let's scroll it to the former place
-            String scrolling = (String) externalContext
-                    .getRequestParameterMap().get(AUTO_SCROLL_PARAM);
-            if (scrolling != null && scrolling.length() > 0)
-            {
-                int x = 0;
-                int y = 0;
-                int comma = scrolling.indexOf(',');
-                if (comma == -1)
-                {
-                    log.warning("Illegal autoscroll request parameter: "
-                            + scrolling);
-                }
-                else
-                {
-                    try
-                    {
-                        //we convert to int against XSS vulnerability
-                        x = Integer.parseInt(scrolling.substring(0, comma));
-                    }
-                    catch (NumberFormatException e)
-                    {
-                        log.warning("Error getting x offset for autoscroll feature. Bad param value: "
-                                + scrolling);
-                        x = 0; //ignore false numbers
-                    }
-
-                    try
-                    {
-                        //we convert to int against XSS vulnerability
-                        y = Integer.parseInt(scrolling.substring(comma + 1));
-                    }
-                    catch (NumberFormatException e)
-                    {
-                        log.warning("Error getting y offset for autoscroll feature. Bad param value: "
-                                + scrolling);
-                        y = 0; //ignore false numbers
-                    }
-                }
-                script.append("window.scrollTo(").append(x).append(",")
-                        .append(y).append(");\n");
-            }
-        }
-
-        return script.toString();
-    }
-    
-    /**
-     * Renders the hidden form input that is necessary for the autoscroll feature.
-     */
-    public static void renderAutoScrollHiddenInput(FacesContext facesContext,
-            ResponseWriter writer) throws IOException
-    {
-        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-        writer.startElement(HTML.INPUT_ELEM, null);
-        writer.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
-        writer.writeAttribute(HTML.NAME_ATTR, AUTO_SCROLL_PARAM, null);
-        writer.endElement(HTML.INPUT_ELEM);
-        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-    }
-
-    /**
-     * Renders the autoscroll javascript function.
-     */
-    public static void renderAutoScrollFunction(FacesContext facesContext,
-            ResponseWriter writer) throws IOException
-    {
-        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-        writer.startElement(HTML.SCRIPT_ELEM, null);
-        writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR,
-                HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-        writer.writeText(getAutoScrollFunction(facesContext), null);
-        writer.endElement(HTML.SCRIPT_ELEM);
-        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-    }
-    
-    public static void appendClearHiddenCommandFormParamsFunctionCall(
-            StringBuilder buf, String formName)
-    {
-        appendClearHiddenCommandFormParamsFunctionCall(new ScriptContext(buf,
-                false), formName);
-    }
-    
-    private static void appendClearHiddenCommandFormParamsFunctionCall(
-            ScriptContext context, String formName)
-    {
-        String functionName = HtmlRendererUtils
-                .getClearHiddenCommandFormParamsFunctionName(formName);
-        if (formName == null)
-        {
-            context.prettyLine();
-            context.append("var clearFn = ");
-            context.append(functionName);
-            context.append(";");
-            context.prettyLine();
-            context.append("if(typeof window[clearFn] =='function')");
-            context.append("{");
-            context.append("window[clearFn](formName);");
-            context.append("}");
-        }
-        else
-        {
-            context.prettyLine();
-            context.append("if(typeof window.");
-            context.append(functionName);
-            context.append("=='function')");
-            context.append("{");
-            context.append(functionName).append("('").append(formName)
-                    .append("');");
-            context.append("}");
-        }
-    }
-    
-    /**
-     * Prefixes the given String with "clear_" and removes special characters
-     *
-     * @param formName
-     * @return String
-     */
-    public static String getClearHiddenCommandFormParamsFunctionName(
-            String formName)
-    {
-        final char separatorChar = UINamingContainer
-                .getSeparatorChar(FacesContext.getCurrentInstance());
-        if (formName == null)
-        {
-            return "'" + HtmlRendererUtils.CLEAR_HIDDEN_FIELD_FN_NAME
-                    + "_'+formName.replace(/-/g, '\\$" + separatorChar
-                    + "').replace(/" + separatorChar + "/g,'_')";
-        }
-
-        return JavascriptUtils
-                .getValidJavascriptNameAsInRI(HtmlRendererUtils.CLEAR_HIDDEN_FIELD_FN_NAME + "_"
-                        + formName.replace(separatorChar, '_'));
-    }
-
-    public static String getClearHiddenCommandFormParamsFunctionNameMyfacesLegacy(
-            String formName)
-    {
-        return "clear_"
-                + JavascriptUtils.getValidJavascriptName(formName, false);
-    }
-    
-    /**
-     * Render the javascript function that is called on a click on a commandLink
-     * to clear the hidden inputs. This is necessary because on a browser back,
-     * each hidden input still has it's old value (browser cache!) and therefore
-     * a new submit would cause the according action once more!
-     *
-     * @param writer
-     * @param formName
-     * @param dummyFormParams
-     * @param formTarget
-     * @throws IOException
-     */
-    public static void renderClearHiddenCommandFormParamsFunction(
-            ResponseWriter writer, String formName, Set dummyFormParams,
-            String formTarget) throws IOException
-    {
-        //render the clear hidden inputs javascript function
-        String functionName = getClearHiddenCommandFormParamsFunctionName(formName);
-        writer.startElement(HTML.SCRIPT_ELEM, null);
-        writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
-
-        // Using writeComment instead of write with <!-- tag
-        StringBuilder script = new StringBuilder();
-        script.append("function ");
-        script.append(functionName);
-        script.append("() {");
-        if (dummyFormParams != null)
-        {
-            script.append("\n  var f = document.forms['");
-            script.append(formName);
-            script.append("'];");
-            int i = 0;
-            for (Iterator it = dummyFormParams.iterator(); it.hasNext();)
-            {
-                String elemVarName = "elem" + i;
-                script.append("\n  var ").append(elemVarName).append(" = ");
-                script.append("f.elements['").append((String) it.next())
-                        .append("'];");
-                script.append("\n  if(typeof ").append(elemVarName)
-                        .append(" !='undefined' && ");
-                script.append(elemVarName).append(".nodeName=='INPUT'){");
-                script.append("\n   if (").append(elemVarName)
-                        .append(".value != '') {");
-                script.append("\n    " + elemVarName + ".value='';");
-                script.append("\n   }");
-                script.append("\n  }");
-                i++;
-            }
-        }
-        // clear form target
-        script.append("\n  f.target=");
-        if (formTarget == null || formTarget.length() == 0)
-        {
-            //Normally one would think that setting target to null has the
-            //desired effect, but once again IE is different...
-            //Setting target to null causes IE to open a new window!
-            script.append("'';");
-        }
-        else
-        {
-            script.append("'");
-            script.append(formTarget);
-            script.append("';");
-        }
-        script.append("\n}");
-
-        //Just to be sure we call this clear method on each load.
-        //Otherwise in the case, that someone submits a form by pressing Enter
-        //within a text input, the hidden inputs won't be cleared!
-        script.append("\n");
-        script.append(functionName);
-        script.append("();");
-
-        writer.writeText(script.toString(), null);
-        writer.endElement(HTML.SCRIPT_ELEM);
-    }
-    
-    /**
-     * This function correctly escapes the given JavaScript code
-     * for the use in the jsf.util.chain() JavaScript function.
-     * It also handles double-escaping correclty.
-     *
-     * @param javaScript
-     * @return
-     */
-    public static String escapeJavaScriptForChain(String javaScript)
-    {
-        // first replace \' with \\'
-        //String escaped = StringUtils.replace(javaScript, "\\'", "\\\\'");
-
-        // then replace ' with \'
-        // (this will replace every \' in the original to \\\')
-        //escaped = StringUtils.replace(escaped, '\'', "\\'");
-
-        //return escaped;
-
-        StringBuilder out = null;
-        for (int pos = 0; pos < javaScript.length(); pos++)
-        {
-            char c = javaScript.charAt(pos);
-
-            if (c == '\\' || c == '\'')
-            {
-                if (out == null)
-                {
-                    out = new StringBuilder(javaScript.length() + 8);
-                    if (pos > 0)
-                    {
-                        out.append(javaScript, 0, pos);
-                    }
-                }
-                out.append('\\');
-            }
-            if (out != null)
-            {
-                out.append(c);
-            }
-        }
-
-        if (out == null)
-        {
-            return javaScript;
-        }
-        else
-        {
-            return out.toString();
-        }
-    }
-    
-    public static void renderViewStateJavascript(FacesContext facesContext,
-            String hiddenId, String serializedState) throws IOException
-    {
-        ResponseWriter writer = facesContext.getResponseWriter();
-
-        writer.startElement(HTML.SCRIPT_ELEM, null);
-        writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
-
-        final ExternalContext externalContext = facesContext
-                .getExternalContext();
-        final MyfacesConfig currentInstance = MyfacesConfig
-                .getCurrentInstance(externalContext);
-
-        ScriptContext context = new ScriptContext(
-                currentInstance.isPrettyHtml());
-        context.prettyLine();
-        context.increaseIndent();
-
-        context.append("function setViewState() {\n");
-        context.append("\tvar state = '");
-        context.append(serializedState);
-        context.append("';\n");
-        context.append("\tfor (var i = 0; i < document.forms.length; i++) {\n");
-        context.append("\t\tdocument.forms[i]['" + hiddenId
-                + "'].value = state;\n");
-        context.append("\t}\n");
-        context.append("}\n");
-        context.append("setViewState();\n");
-
-        context.decreaseIndent();
-
-        writer.writeText(context.toString(), null);
-
-        writer.endElement(HTML.SCRIPT_ELEM);
-    }
-}
+/*
+ * 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.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.faces.component.UINamingContainer;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.shared.config.MyfacesConfig;
+import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils.ScriptContext;
+import org.apache.myfaces.shared.renderkit.html.util.JavascriptUtils;
+import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
+
+public final class HtmlJavaScriptUtils
+{
+    private static final Logger log = Logger.getLogger(HtmlJavaScriptUtils.class
+            .getName());
+
+    private static final String AUTO_SCROLL_PARAM = "autoScroll";
+    private static final String AUTO_SCROLL_FUNCTION = "getScrolling";
+
+    private static final String SET_HIDDEN_INPUT_FN_NAME = "oamSetHiddenInput";
+    private static final String SET_HIDDEN_INPUT_FN_NAME_JSF2 = "myfaces.oam.setHiddenInput";
+
+    private static final String FIRST_SUBMIT_SCRIPT_ON_PAGE = "org.apache.MyFaces.FIRST_SUBMIT_SCRIPT_ON_PAGE";
+    private static final String CLEAR_HIDDEN_INPUT_FN_NAME = "oamClearHiddenInput";
+    
+
+    @SuppressWarnings("unchecked")
+    public static void renderFormSubmitScript(FacesContext facesContext)
+            throws IOException
+    {
+
+        Map map = facesContext.getExternalContext().getRequestMap();
+        Boolean firstScript = (Boolean) map.get(FIRST_SUBMIT_SCRIPT_ON_PAGE);
+
+        if (firstScript == null || firstScript.equals(Boolean.TRUE))
+        {
+            map.put(FIRST_SUBMIT_SCRIPT_ON_PAGE, Boolean.FALSE);
+            renderFormSubmitScriptIfNecessary(facesContext);
+
+            //we have to render the config just in case
+            renderConfigOptionsIfNecessary(facesContext);
+        }
+    }
+    
+    /**
+     * @param facesContext
+     * @throws IOException
+     */
+    private static void renderFormSubmitScriptIfNecessary(
+            FacesContext facesContext) throws IOException
+    {
+        final ExternalContext externalContext = facesContext
+                .getExternalContext();
+        final MyfacesConfig currentInstance = MyfacesConfig
+                .getCurrentInstance(externalContext);
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        if (currentInstance.isRenderFormSubmitScriptInline())
+        {
+            writer.startElement(HTML.SCRIPT_ELEM, null);
+            writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+
+            boolean autoScroll = currentInstance.isAutoScroll();
+
+            ScriptContext context = new ScriptContext(
+                    currentInstance.isPrettyHtml());
+            context.prettyLine();
+            context.increaseIndent();
+
+            prepareScript(facesContext, context, autoScroll);
+
+            writer.writeText(context.toString(), null);
+
+            writer.endElement(HTML.SCRIPT_ELEM);
+        }
+        else
+        {
+            ResourceUtils
+                    .renderMyfacesJSInlineIfNecessary(facesContext, writer);
+        }
+    }
+    
+    private static void renderConfigOptionsIfNecessary(FacesContext facesContext)
+            throws IOException
+    {
+        ResponseWriter writer = facesContext.getResponseWriter();
+        MyfacesConfig config = MyfacesConfig.getCurrentInstance(facesContext
+                .getExternalContext());
+        ScriptContext script = new ScriptContext(config.isPrettyHtml());
+        boolean autoScroll = config.isAutoScroll();
+        boolean autoSave = JavascriptUtils.isSaveFormSubmitLinkIE(facesContext
+                .getExternalContext());
+
+        if (autoScroll || autoSave)
+        {
+            script.prettyLine();
+            script.increaseIndent();
+            script.append("(!window.myfaces) ? window.myfaces = {} : null;");
+            script.append("(!myfaces.core) ? myfaces.core = {} : null;");
+            script.append("(!myfaces.core.config) ? myfaces.core.config = {} : null;");
+        }
+
+        if (autoScroll)
+        {
+            script.append("myfaces.core.config.autoScroll = true;");
+        }
+        if (autoSave)
+        {
+            script.append("myfaces.core.config.ieAutoSave = true;");
+        }
+        if (autoScroll || autoSave)
+        {
+            writer.startElement(HTML.SCRIPT_ELEM, null);
+            writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+            writer.writeText(script.toString(), null);
+            writer.endElement(HTML.SCRIPT_ELEM);
+        }
+    }
+    /**
+     * @param facesContext
+     * @param context
+     * @param autoScroll
+     */
+    private static void prepareScript(FacesContext facesContext,
+            ScriptContext context, boolean autoScroll)
+    {
+
+        final char separatorChar = UINamingContainer
+                .getSeparatorChar(facesContext);
+        context.prettyLine();
+
+        //render a function to create a hidden input, if it doesn't exist
+        context.append("function ");
+        context.append(SET_HIDDEN_INPUT_FN_NAME).append(
+                "(formname, name, value)");
+        context.append("{");
+        context.append("var form = document.forms[formname];");
+        context.prettyLine();
+        context.append("if (typeof form == 'undefined')");
+        context.append("{");
+        context.append("form = document.getElementById(formname);");
+        context.append("}");
+        context.prettyLine();
+        context.append("if(typeof form.elements[name]!='undefined' && "+
+                "(form.elements[name].nodeName=='INPUT' || form.elements[name].nodeName=='input'))");
+        context.append("{");
+        context.append("form.elements[name].value=value;");
+        context.append("}");
+        context.append("else");
+        context.append("{");
+        context.append("var newInput = document.createElement('input');");
+        context.prettyLine();
+        context.append("newInput.setAttribute('type','hidden');");
+        context.prettyLine();
+        context.append("newInput.setAttribute('id',name);"); // IE hack; See MYFACES-1805
+        context.prettyLine();
+        context.append("newInput.setAttribute('name',name);");
+        context.prettyLine();
+        context.append("newInput.setAttribute('value',value);");
+        context.prettyLine();
+        context.append("form.appendChild(newInput);");
+        context.append("}");
+
+        context.append("}");
+
+        context.prettyLine();
+
+        context.prettyLine();
+
+        //render a function to clear a hidden input, if it exists        
+        context.append("function ");
+        context.append(CLEAR_HIDDEN_INPUT_FN_NAME).append(
+                "(formname, name, value)");
+        context.append("{");
+        context.append("var form = document.forms[formname];");
+        context.prettyLine();
+        context.append("if (typeof form == 'undefined')");
+        context.append("{");
+        context.append("form = document.getElementById(formname);");
+        context.append("}");
+        context.prettyLine();
+        context.append("var hInput = form.elements[name];");
+        context.prettyLine();
+        context.append("if(typeof hInput !='undefined')");
+        context.append("{");
+        //context.append("form.elements[name].value=null;");
+        context.append("form.removeChild(hInput);");
+        context.append("}");
+
+        context.append("}");
+
+        context.prettyLine();
+
+        context.append("function ");
+        context.append(HtmlRendererUtils.SUBMIT_FORM_FN_NAME).append(
+                "(formName, linkId, target, params)");
+        context.append("{");
+
+        //call the script to clear the form (clearFormHiddenParams_<formName>) method - 
+        //optionally, only necessary for IE5.5.
+        //todo: if IE5.5. is ever desupported, we can get rid of this and instead rely on 
+        //the last part of this script to
+        //clear the parameters
+        appendClearHiddenCommandFormParamsFunctionCall(
+                context, null);
+
+        if (autoScroll)
+        {
+            appendAutoScrollAssignment(facesContext, context, null);
+        }
+
+        context.prettyLine();
+
+        context.append("var form = document.forms[formName];");
+        context.prettyLine();
+        context.append("if (typeof form == 'undefined')");
+        context.append("{");
+        context.append("form = document.getElementById(formName);");
+        context.append("}");
+        context.prettyLine();
+
+        if (JavascriptUtils.isSaveFormSubmitLinkIE(FacesContext
+                .getCurrentInstance().getExternalContext()))
+        {
+            context.append("var agentString = navigator.userAgent.toLowerCase();");
+            context.prettyLine();
+            //context.append("var isIE = false;");
+            context.prettyLine();
+            context.append("if (agentString.indexOf('msie') != -1)");
+
+            context.append("{");
+            context.append("if (!(agentString.indexOf('ppc') != -1 &&"+
+                    " agentString.indexOf('windows ce') != -1 && version >= 4.0))");
+            context.append("{");
+            context.append("window.external.AutoCompleteSaveForm(form);");
+            //        context.append("isIE = false;");
+            context.append("}");
+            //        context.append("else");
+            //        context.append("{");
+            //        context.append("isIE = true;");
+            //        context.prettyLine();
+            //        context.append("}");
+
+            context.append("}");
+
+            context.prettyLine();
+        }
+        //set the target (and save it). This should be done always, 
+        //and the default value of target is always valid.
+        context.append("var oldTarget = form.target;");
+        context.prettyLine();
+        context.append("if(target != null)");
+        context.append("{");
+        context.prettyLine();
+        context.append("form.target=target;");
+        context.append("}");
+
+        //set the submit parameters
+
+        context.append("if((typeof params!='undefined') && params != null)");
+        context.append("{");
+        context.prettyLine();
+        context.append("for(var i=0, param; (param = params[i]); i++)");
+        context.append("{");
+        context.append(SET_HIDDEN_INPUT_FN_NAME).append(
+                "(formName,param[0], param[1]);");
+        context.append("}");
+        context.append("}");
+
+        context.prettyLine();
+
+        context.append(SET_HIDDEN_INPUT_FN_NAME);
+        context.append("(formName,formName +'" + separatorChar + "'+'"
+                + HtmlRendererUtils.HIDDEN_COMMANDLINK_FIELD_NAME
+                + "',linkId);");
+
+        context.prettyLine();
+        context.prettyLine();
+
+        //do the actual submit calls
+
+        context.append("if(form.onsubmit)");
+        context.append("{");
+        context.append("var result=form.onsubmit();");
+        context.prettyLine();
+        context.append("if((typeof result=='undefined')||result)");
+        context.append("{");
+        context.append("try");
+        context.append("{");
+        context.append("form.submit();");
+        context.append("}");
+        context.append("catch(e){}");
+        context.append("}");
+        context.append("}");
+        context.append("else ");
+        context.append("{");
+        context.append("try");
+        context.append("{");
+        context.append("form.submit();");
+        context.append("}");
+        context.append("catch(e){}");
+        context.append("}");
+
+        //reset the target
+        context.prettyLine();
+        //Restore the old target, no more questions asked
+        context.append("form.target=oldTarget;");
+        context.prettyLine();
+
+        //clear the individual parameters - to make sure that even if the clear-function isn't called,
+        // the back button/resubmit functionality will still work in all browsers except IE 5.5.
+
+        context.append("if((typeof params!='undefined') && params != null)");
+        context.append("{");
+        context.prettyLine();
+        context.append("for(var i=0, param; (param = params[i]); i++)");
+        context.append("{");
+        context.append(CLEAR_HIDDEN_INPUT_FN_NAME).append(
+                "(formName,param[0], param[1]);");
+        context.append("}");
+        context.append("}");
+
+        context.prettyLine();
+
+        context.append(CLEAR_HIDDEN_INPUT_FN_NAME);
+        context.append("(formName,formName +'" + separatorChar + "'+'"
+                + HtmlRendererUtils.HIDDEN_COMMANDLINK_FIELD_NAME
+                + "',linkId);");
+
+        //return false, so that browser does not handle the click
+        context.append("return false;");
+        context.append("}");
+
+        context.prettyLineDecreaseIndent();
+    }
+    
+    public static void appendAutoScrollAssignment(StringBuilder onClickValue,
+            String formName)
+    {
+        appendAutoScrollAssignment(FacesContext.getCurrentInstance(),
+                new ScriptContext(onClickValue, false), formName);
+    }
+
+    /**
+     * 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(FacesContext context,
+            StringBuilder onClickValue, String formName)
+    {
+        appendAutoScrollAssignment(context, new ScriptContext(onClickValue,
+                false), formName);
+    }
+    
+    private static void appendAutoScrollAssignment(FacesContext context,
+            ScriptContext scriptContext, String formName)
+    {
+        String formNameStr = formName == null ? "formName" : (new StringBuilder(
+                "'").append(formName).append("'").toString());
+        String paramName = new StringBuilder().append("'")
+                .append(AUTO_SCROLL_PARAM).append("'").toString();
+        String value = new StringBuilder().append(AUTO_SCROLL_FUNCTION)
+                .append("()").toString();
+
+        scriptContext.prettyLine();
+        scriptContext.append("if(typeof window." + AUTO_SCROLL_FUNCTION
+                + "!='undefined')");
+        scriptContext.append("{");
+        if (MyfacesConfig.getCurrentInstance(context.getExternalContext())
+                .isRenderFormSubmitScriptInline())
+        {
+            scriptContext.append(SET_HIDDEN_INPUT_FN_NAME);
+        }
+        else
+        {
+            scriptContext.append(SET_HIDDEN_INPUT_FN_NAME_JSF2);
+        }
+        scriptContext.append("(").append(formNameStr).append(",")
+                .append(paramName).append(",").append(value).append(");");
+        scriptContext.append("}");
+
+    }
+    
+    public static String getAutoScrollFunction(FacesContext facesContext)
+    {
+        ScriptContext script = new ScriptContext(MyfacesConfig
+                .getCurrentInstance(facesContext.getExternalContext())
+                .isPrettyHtml());
+
+        script.prettyLineIncreaseIndent();
+
+        script.append("function ");
+        script.append(AUTO_SCROLL_FUNCTION);
+        script.append("()");
+        script.append("{");
+        script.append("var x = 0; var y = 0;");
+        script.append("if (self.pageXOffset || self.pageYOffset)");
+        script.append("{");
+        script.append("x = self.pageXOffset;");
+        script.prettyLine();
+        script.append("y = self.pageYOffset;");
+        script.append("}");
+        script.append(" else if ((document.documentElement && document.documentElement.scrollLeft)||"+
+                "(document.documentElement && document.documentElement.scrollTop))");
+        script.append("{");
+        script.append("x = document.documentElement.scrollLeft;");
+        script.prettyLine();
+        script.append("y = document.documentElement.scrollTop;");
+        script.append("}");
+        script.append(" else if (document.body) ");
+        script.append("{");
+        script.append("x = document.body.scrollLeft;");
+        script.prettyLine();
+        script.append("y = document.body.scrollTop;");
+        script.append("}");
+        script.append("return x + \",\" + y;");
+        script.append("}");
+
+        ExternalContext externalContext = facesContext.getExternalContext();
+        String oldViewId = JavascriptUtils.getOldViewId(externalContext);
+        if (oldViewId != null
+                && oldViewId.equals(facesContext.getViewRoot().getViewId()))
+        {
+            //ok, we stayed on the same page, so let's scroll it to the former place
+            String scrolling = (String) externalContext
+                    .getRequestParameterMap().get(AUTO_SCROLL_PARAM);
+            if (scrolling != null && scrolling.length() > 0)
+            {
+                int x = 0;
+                int y = 0;
+                int comma = scrolling.indexOf(',');
+                if (comma == -1)
+                {
+                    log.warning("Illegal autoscroll request parameter: "
+                            + scrolling);
+                }
+                else
+                {
+                    try
+                    {
+                        //we convert to int against XSS vulnerability
+                        x = Integer.parseInt(scrolling.substring(0, comma));
+                    }
+                    catch (NumberFormatException e)
+                    {
+                        log.warning("Error getting x offset for autoscroll feature. Bad param value: "
+                                + scrolling);
+                        x = 0; //ignore false numbers
+                    }
+
+                    try
+                    {
+                        //we convert to int against XSS vulnerability
+                        y = Integer.parseInt(scrolling.substring(comma + 1));
+                    }
+                    catch (NumberFormatException e)
+                    {
+                        log.warning("Error getting y offset for autoscroll feature. Bad param value: "
+                                + scrolling);
+                        y = 0; //ignore false numbers
+                    }
+                }
+                script.append("window.scrollTo(").append(x).append(",")
+                        .append(y).append(");\n");
+            }
+        }
+
+        return script.toString();
+    }
+    
+    /**
+     * Renders the hidden form input that is necessary for the autoscroll feature.
+     */
+    public static void renderAutoScrollHiddenInput(FacesContext facesContext,
+            ResponseWriter writer) throws IOException
+    {
+        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+        writer.startElement(HTML.INPUT_ELEM, null);
+        writer.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
+        writer.writeAttribute(HTML.NAME_ATTR, AUTO_SCROLL_PARAM, null);
+        writer.endElement(HTML.INPUT_ELEM);
+        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+    }
+
+    /**
+     * Renders the autoscroll javascript function.
+     */
+    public static void renderAutoScrollFunction(FacesContext facesContext,
+            ResponseWriter writer) throws IOException
+    {
+        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+        writer.startElement(HTML.SCRIPT_ELEM, null);
+        writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR,
+                HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+        writer.writeText(getAutoScrollFunction(facesContext), null);
+        writer.endElement(HTML.SCRIPT_ELEM);
+        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+    }
+    
+    public static void appendClearHiddenCommandFormParamsFunctionCall(
+            StringBuilder buf, String formName)
+    {
+        appendClearHiddenCommandFormParamsFunctionCall(new ScriptContext(buf,
+                false), formName);
+    }
+    
+    private static void appendClearHiddenCommandFormParamsFunctionCall(
+            ScriptContext context, String formName)
+    {
+        String functionName = HtmlRendererUtils
+                .getClearHiddenCommandFormParamsFunctionName(formName);
+        if (formName == null)
+        {
+            context.prettyLine();
+            context.append("var clearFn = ");
+            context.append(functionName);
+            context.append(";");
+            context.prettyLine();
+            context.append("if(typeof window[clearFn] =='function')");
+            context.append("{");
+            context.append("window[clearFn](formName);");
+            context.append("}");
+        }
+        else
+        {
+            context.prettyLine();
+            context.append("if(typeof window.");
+            context.append(functionName);
+            context.append("=='function')");
+            context.append("{");
+            context.append(functionName).append("('").append(formName)
+                    .append("');");
+            context.append("}");
+        }
+    }
+    
+    /**
+     * Prefixes the given String with "clear_" and removes special characters
+     *
+     * @param formName
+     * @return String
+     */
+    public static String getClearHiddenCommandFormParamsFunctionName(
+            String formName)
+    {
+        final char separatorChar = UINamingContainer
+                .getSeparatorChar(FacesContext.getCurrentInstance());
+        if (formName == null)
+        {
+            return "'" + HtmlRendererUtils.CLEAR_HIDDEN_FIELD_FN_NAME
+                    + "_'+formName.replace(/-/g, '\\$" + separatorChar
+                    + "').replace(/" + separatorChar + "/g,'_')";
+        }
+
+        return JavascriptUtils
+                .getValidJavascriptNameAsInRI(HtmlRendererUtils.CLEAR_HIDDEN_FIELD_FN_NAME + "_"
+                        + formName.replace(separatorChar, '_'));
+    }
+
+    public static String getClearHiddenCommandFormParamsFunctionNameMyfacesLegacy(
+            String formName)
+    {
+        return "clear_"
+                + JavascriptUtils.getValidJavascriptName(formName, false);
+    }
+    
+    /**
+     * Render the javascript function that is called on a click on a commandLink
+     * to clear the hidden inputs. This is necessary because on a browser back,
+     * each hidden input still has it's old value (browser cache!) and therefore
+     * a new submit would cause the according action once more!
+     *
+     * @param writer
+     * @param formName
+     * @param dummyFormParams
+     * @param formTarget
+     * @throws IOException
+     */
+    public static void renderClearHiddenCommandFormParamsFunction(
+            ResponseWriter writer, String formName, Set dummyFormParams,
+            String formTarget) throws IOException
+    {
+        //render the clear hidden inputs javascript function
+        String functionName = getClearHiddenCommandFormParamsFunctionName(formName);
+        writer.startElement(HTML.SCRIPT_ELEM, null);
+        writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+
+        // Using writeComment instead of write with <!-- tag
+        StringBuilder script = new StringBuilder();
+        script.append("function ");
+        script.append(functionName);
+        script.append("() {");
+        if (dummyFormParams != null)
+        {
+            script.append("\n  var f = document.forms['");
+            script.append(formName);
+            script.append("'];");
+            int i = 0;
+            for (Iterator it = dummyFormParams.iterator(); it.hasNext();)
+            {
+                String elemVarName = "elem" + i;
+                script.append("\n  var ").append(elemVarName).append(" = ");
+                script.append("f.elements['").append((String) it.next())
+                        .append("'];");
+                script.append("\n  if(typeof ").append(elemVarName)
+                        .append(" !='undefined' && ");
+                script.append(elemVarName).append(".nodeName=='INPUT'){");
+                script.append("\n   if (").append(elemVarName)
+                        .append(".value != '') {");
+                script.append("\n    " + elemVarName + ".value='';");
+                script.append("\n   }");
+                script.append("\n  }");
+                i++;
+            }
+        }
+        // clear form target
+        script.append("\n  f.target=");
+        if (formTarget == null || formTarget.length() == 0)
+        {
+            //Normally one would think that setting target to null has the
+            //desired effect, but once again IE is different...
+            //Setting target to null causes IE to open a new window!
+            script.append("'';");
+        }
+        else
+        {
+            script.append("'");
+            script.append(formTarget);
+            script.append("';");
+        }
+        script.append("\n}");
+
+        //Just to be sure we call this clear method on each load.
+        //Otherwise in the case, that someone submits a form by pressing Enter
+        //within a text input, the hidden inputs won't be cleared!
+        script.append("\n");
+        script.append(functionName);
+        script.append("();");
+
+        writer.writeText(script.toString(), null);
+        writer.endElement(HTML.SCRIPT_ELEM);
+    }
+    
+    /**
+     * This function correctly escapes the given JavaScript code
+     * for the use in the jsf.util.chain() JavaScript function.
+     * It also handles double-escaping correclty.
+     *
+     * @param javaScript
+     * @return
+     */
+    public static String escapeJavaScriptForChain(String javaScript)
+    {
+        // first replace \' with \\'
+        //String escaped = StringUtils.replace(javaScript, "\\'", "\\\\'");
+
+        // then replace ' with \'
+        // (this will replace every \' in the original to \\\')
+        //escaped = StringUtils.replace(escaped, '\'', "\\'");
+
+        //return escaped;
+
+        StringBuilder out = null;
+        for (int pos = 0; pos < javaScript.length(); pos++)
+        {
+            char c = javaScript.charAt(pos);
+
+            if (c == '\\' || c == '\'')
+            {
+                if (out == null)
+                {
+                    out = new StringBuilder(javaScript.length() + 8);
+                    if (pos > 0)
+                    {
+                        out.append(javaScript, 0, pos);
+                    }
+                }
+                out.append('\\');
+            }
+            if (out != null)
+            {
+                out.append(c);
+            }
+        }
+
+        if (out == null)
+        {
+            return javaScript;
+        }
+        else
+        {
+            return out.toString();
+        }
+    }
+    
+    public static void renderViewStateJavascript(FacesContext facesContext,
+            String hiddenId, String serializedState) throws IOException
+    {
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        writer.startElement(HTML.SCRIPT_ELEM, null);
+        writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+
+        final ExternalContext externalContext = facesContext
+                .getExternalContext();
+        final MyfacesConfig currentInstance = MyfacesConfig
+                .getCurrentInstance(externalContext);
+
+        ScriptContext context = new ScriptContext(
+                currentInstance.isPrettyHtml());
+        context.prettyLine();
+        context.increaseIndent();
+
+        context.append("function setViewState() {\n");
+        context.append("\tvar state = '");
+        context.append(serializedState);
+        context.append("';\n");
+        context.append("\tfor (var i = 0; i < document.forms.length; i++) {\n");
+        context.append("\t\tdocument.forms[i]['" + hiddenId
+                + "'].value = state;\n");
+        context.append("\t}\n");
+        context.append("}\n");
+        context.append("setViewState();\n");
+
+        context.decreaseIndent();
+
+        writer.writeText(context.toString(), null);
+
+        writer.endElement(HTML.SCRIPT_ELEM);
+    }
+}

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessageRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessageRendererBase.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessageRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessageRendererBase.java Tue Apr 16 22:49:45 2013
@@ -107,7 +107,7 @@ public abstract class HtmlMessageRendere
             if (alwaysRenderSpan)
             {
                 ResponseWriter writer = facesContext.getResponseWriter();
-                writer.startElement(HTML.SPAN_ELEM, null);
+                writer.startElement(HTML.SPAN_ELEM, message);
                 writer.writeAttribute(HTML.ID_ATTR, clientId + "_msgFor", null);
                 HtmlRendererUtils.renderHTMLStringAttribute(writer, message, JSFAttr.STYLE_ATTR, HTML.STYLE_ATTR);
                 HtmlRendererUtils.renderHTMLStringAttribute(writer, message, JSFAttr.STYLE_CLASS_ATTR, HTML.CLASS_ATTR);

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessagesRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessagesRendererBase.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessagesRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlMessagesRendererBase.java Tue Apr 16 22:49:45 2013
@@ -184,7 +184,7 @@ public abstract class HtmlMessagesRender
 
         while(messagesIterator.hasNext())
         {
-            writer.startElement(org.apache.myfaces.shared.renderkit.html.HTML.LI_ELEM, messages);
+            writer.startElement(org.apache.myfaces.shared.renderkit.html.HTML.LI_ELEM, null); //messages);
             
             FacesMessage facesMessage = (FacesMessage)messagesIterator.next();
             // determine style and style class
@@ -237,8 +237,8 @@ public abstract class HtmlMessagesRender
         
         while(messagesIterator.hasNext())
         {
-            writer.startElement(HTML.TR_ELEM, messages);
-            writer.startElement(HTML.TD_ELEM, messages);
+            writer.startElement(HTML.TR_ELEM, null); // messages);
+            writer.startElement(HTML.TD_ELEM, null); // messages);
             
             FacesMessage facesMessage = (FacesMessage)messagesIterator.next();
             // determine style and style class

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRadioRendererBase.java Tue Apr 16 22:49:45 2013
@@ -112,7 +112,7 @@ public class HtmlRadioRendererBase
 
         if (!pageDirectionLayout)
         {
-            writer.startElement(HTML.TR_ELEM, selectOne);
+            writer.startElement(HTML.TR_ELEM, null); // selectOne);
         }
 
         Converter converter;
@@ -190,10 +190,10 @@ public class HtmlRadioRendererBase
         {
             if (pageDirectionLayout)
             {
-                writer.startElement(HTML.TR_ELEM, selectOne);
+                writer.startElement(HTML.TR_ELEM, null); // selectOne);
             }
 
-            writer.startElement(HTML.TD_ELEM, selectOne);
+            writer.startElement(HTML.TD_ELEM, null); // selectOne);
             if (selectItem.isEscape())
             {
                 writer.writeText(selectItem.getLabel(),HTML.LABEL_ATTR);
@@ -207,16 +207,16 @@ public class HtmlRadioRendererBase
             if (pageDirectionLayout)
             {
                 writer.endElement(HTML.TR_ELEM);
-                writer.startElement(HTML.TR_ELEM, selectOne);
+                writer.startElement(HTML.TR_ELEM, null); // selectOne);
             }
-            writer.startElement(HTML.TD_ELEM, selectOne);
+            writer.startElement(HTML.TD_ELEM, null); // selectOne);
 
-            writer.startElement(HTML.TABLE_ELEM, selectOne);
+            writer.startElement(HTML.TABLE_ELEM, null); // selectOne);
             writer.writeAttribute(HTML.BORDER_ATTR, "0", null);
             
             if(!pageDirectionLayout)
             {
-                writer.startElement(HTML.TR_ELEM, selectOne);
+                writer.startElement(HTML.TR_ELEM, null); // selectOne);
             }
 
             SelectItemGroup group = (SelectItemGroup) selectItem;
@@ -265,9 +265,9 @@ public class HtmlRadioRendererBase
             writer.write("\t\t");
             if (pageDirectionLayout)
             {
-                writer.startElement(HTML.TR_ELEM, selectOne);
+                writer.startElement(HTML.TR_ELEM, null); // selectOne);
             }
-            writer.startElement(HTML.TD_ELEM, selectOne);
+            writer.startElement(HTML.TD_ELEM, null); // selectOne);
     
             boolean itemDisabled = selectItem.isDisabled();
     

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlRendererUtils.java Tue Apr 16 22:49:45 2013
@@ -548,7 +548,7 @@ public final class HtmlRendererUtils
             SelectItem selectItem = (SelectItem) it.next();
             if (selectItem instanceof SelectItemGroup)
             {
-                writer.startElement(HTML.OPTGROUP_ELEM, component);
+                writer.startElement(HTML.OPTGROUP_ELEM, null); // component);
                 writer.writeAttribute(HTML.LABEL_ATTR, selectItem.getLabel(),
                         null);
                 SelectItem[] selectItems = ((SelectItemGroup) selectItem)
@@ -581,7 +581,7 @@ public final class HtmlRendererUtils
                 }
 
                 writer.write(TABULATOR);
-                writer.startElement(HTML.OPTION_ELEM, component);
+                writer.startElement(HTML.OPTION_ELEM, null); // component);
                 if (itemStrValue != null)
                 {
                     writer.writeAttribute(HTML.VALUE_ATTR, itemStrValue, null);
@@ -1118,7 +1118,7 @@ public final class HtmlRendererUtils
                     //only when useSubmittedValue==true, else use the real item value Objects
                     if (!isSelectOne)
                     {
-                        writer.startElement(HTML.LI_ELEM, component);
+                        writer.startElement(HTML.LI_ELEM, null); // component);
                     }
                     writer.writeText(selectItem.getLabel(), null);
                     if (!isSelectOne)
@@ -1165,7 +1165,7 @@ public final class HtmlRendererUtils
                     .get(org.apache.myfaces.shared.renderkit.JSFAttr.CAPTION_STYLE_ATTR);
         }
         HtmlRendererUtils.writePrettyLineSeparator(context);
-        writer.startElement(HTML.CAPTION_ELEM, component);
+        writer.startElement(HTML.CAPTION_ELEM, null); // component);
         if (captionClass != null)
         {
             writer.writeAttribute(HTML.CLASS_ATTR, captionClass, null);
@@ -1399,7 +1399,7 @@ public final class HtmlRendererUtils
             UIComponent component, String forClientId, String labelValue,
             boolean disabled) throws IOException
     {
-        writer.startElement(HTML.LABEL_ELEM, component);
+        writer.startElement(HTML.LABEL_ELEM, null); // component);
         writer.writeAttribute(HTML.FOR_ATTR, forClientId, null);
         String labelClass = null;
         if (disabled)
@@ -1430,7 +1430,7 @@ public final class HtmlRendererUtils
             UIComponent component, String forClientId, SelectItem item,
             boolean disabled) throws IOException
     {
-        writer.startElement(HTML.LABEL_ELEM, component);
+        writer.startElement(HTML.LABEL_ELEM, null); // component);
         writer.writeAttribute(HTML.FOR_ATTR, forClientId, null);
         String labelClass = null;
         if (disabled)
@@ -1471,7 +1471,7 @@ public final class HtmlRendererUtils
             UIComponent component, String forClientId, SelectItem item,
             boolean disabled, boolean selected) throws IOException
     {
-        writer.startElement(HTML.LABEL_ELEM, component);
+        writer.startElement(HTML.LABEL_ELEM, null); // component);
         writer.writeAttribute(HTML.FOR_ATTR, forClientId, null);
         String labelClass = null;
         if (disabled)

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlResponseWriterImpl.java Tue Apr 16 22:49:45 2013
@@ -21,12 +21,16 @@ package org.apache.myfaces.shared.render
 import java.io.IOException;
 import java.io.Writer;
 import java.nio.charset.Charset;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.el.ValueExpression;
 
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
 
 import org.apache.myfaces.shared.renderkit.ContentTypeUtils;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
@@ -95,6 +99,8 @@ public class HtmlResponseWriterImpl
     private Boolean _isTextArea;
     private UIComponent _startElementUIComponent;
     private boolean _startTagOpen;
+    private Map<String, Object> _passThroughAttributesMap;
+    private FacesContext _facesContext;
 
     private boolean _cdataOpen;
 
@@ -296,6 +302,7 @@ public class HtmlResponseWriterImpl
     public void endDocument() throws IOException
     {
         _currentWriter.flush();
+        _facesContext = null;
     }
 
     public void startElement(String name, UIComponent uiComponent) throws IOException
@@ -307,13 +314,39 @@ public class HtmlResponseWriterImpl
 
         closeStartTagIfNecessary();
         _currentWriter.write('<');
-        _currentWriter.write(name);
 
         resetStartedElement();
 
         _startElementName = name;
         _startElementUIComponent = uiComponent;
         _startTagOpen = true;
+        _passThroughAttributesMap = (_startElementUIComponent != null) ?
+            _startElementUIComponent.getPassThroughAttributes(false) : null;
+
+        if (_passThroughAttributesMap != null)
+        {
+            Object value = _passThroughAttributesMap.get(
+                Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY);
+            if (value != null)
+            {
+                if (value instanceof ValueExpression)
+                {
+                    value = ((ValueExpression)value).getValue(
+                        getFacesContext().getELContext());
+                }
+                String elementName = value.toString().trim();
+                
+                _currentWriter.write((String) elementName);
+            }
+            else
+            {
+                _currentWriter.write(name);
+            }
+        }
+        else
+        {
+            _currentWriter.write(name);
+        }
         
         // Each time we start a element, it is necessary to check <script> or <style>,
         // because we need to buffer all content to post process it later when it reach its end
@@ -357,6 +390,25 @@ public class HtmlResponseWriterImpl
     {
         if (_startTagOpen)
         {
+            if (_passThroughAttributesMap != null)
+            {
+                for (Map.Entry<String, Object> entry : _passThroughAttributesMap.entrySet())
+                {
+                    String key = entry.getKey();
+                    Object value = entry.getValue();
+                    if (Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY.equals(key))
+                    {
+                        // Special attribute stored in passthrough attribute map,
+                        // skip rendering
+                        continue;
+                    }
+                    if (value instanceof ValueExpression)
+                    {
+                        value = ((ValueExpression)value).getValue(getFacesContext().getELContext());
+                    }
+                    encodeAndWriteURIAttribute(key, value, key);
+                }
+            }
             if (!_useStraightXml && isEmptyElement(_startElementName))
             {
                 _currentWriter.write(" />");
@@ -429,6 +481,7 @@ public class HtmlResponseWriterImpl
     {
         _startElementName = null;
         _startElementUIComponent = null;
+        _passThroughAttributesMap = null;
         _isStyle = null;
         _isTextArea = null;
     }
@@ -720,6 +773,12 @@ public class HtmlResponseWriterImpl
             throw new IllegalStateException("Must be called before the start element is closed (attribute '"
                     + name + "')");
         }
+        // From JSF 2.2 RenderKit javadoc: "... If there is a pass through attribute with the same 
+        // name as a renderer specific attribute, the pass through attribute takes precedence. ..."
+        if (_passThroughAttributesMap != null && _passThroughAttributesMap.containsKey(name))
+        {
+            return;
+        }
 
         if (value instanceof Boolean)
         {
@@ -756,7 +815,18 @@ public class HtmlResponseWriterImpl
             throw new IllegalStateException("Must be called before the start element is closed (attribute '"
                     + name + "')");
         }
-
+        // From JSF 2.2 RenderKit javadoc: "... If there is a pass through attribute with the same 
+        // name as a renderer specific attribute, the pass through attribute takes precedence. ..."
+        if (_passThroughAttributesMap != null && _passThroughAttributesMap.containsKey(name))
+        {
+            return;
+        }
+        
+        encodeAndWriteURIAttribute(name, value, componentPropertyName);
+    }
+    
+    private void encodeAndWriteURIAttribute(String name, Object value, String componentPropertyName) throws IOException
+    {
         String strValue = value.toString();
         _currentWriter.write(' ');
         _currentWriter.write(name);
@@ -974,6 +1044,7 @@ public class HtmlResponseWriterImpl
     {
         closeStartTagIfNecessary();
         _currentWriter.close();
+        _facesContext = null;
     }
 
     public void write(char cbuf[], int off, int len) throws IOException
@@ -1070,4 +1141,13 @@ public class HtmlResponseWriterImpl
         }
         return _buffer;
     }
+    
+    protected FacesContext getFacesContext()
+    {
+        if (_facesContext == null)
+        {
+            _facesContext = FacesContext.getCurrentInstance();
+        }
+        return _facesContext;
+    }
 }

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTableRendererBase.java Tue Apr 16 22:49:45 2013
@@ -376,10 +376,10 @@ public class HtmlTableRendererBase exten
         if (rowCount == 0)
         {
             //nothing to render, to get valid xhtml we render an empty dummy row
-            writer.startElement(HTML.TBODY_ELEM, uiData);
+            writer.startElement(HTML.TBODY_ELEM, null); // uiData);
             writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext) + ":tbody_element", null);
-            writer.startElement(HTML.TR_ELEM, uiData);
-            writer.startElement(HTML.TD_ELEM, uiData);
+            writer.startElement(HTML.TR_ELEM, null); // uiData);
+            writer.startElement(HTML.TD_ELEM, null); // uiData);
             writer.endElement(HTML.TD_ELEM);
             writer.endElement(HTML.TR_ELEM);
             writer.endElement(HTML.TBODY_ELEM);
@@ -470,7 +470,7 @@ public class HtmlTableRendererBase exten
                             writer.endElement(HTML.TBODY_ELEM);
                         }
                         HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-                        writer.startElement(HTML.TBODY_ELEM, uiData); 
+                        writer.startElement(HTML.TBODY_ELEM, null); // uiData); 
                         // Do not attach bodyrowsCount to the first TBODY element, because of backward compatibility
                         writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext) + ":tbody_element" + 
                             (bodyrowsCount == 0 ? "" : bodyrowsCount), null);
@@ -571,7 +571,7 @@ public class HtmlTableRendererBase exten
                     writer.endElement(HTML.TBODY_ELEM);
                 }
                 HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-                writer.startElement(HTML.TBODY_ELEM, uiData); 
+                writer.startElement(HTML.TBODY_ELEM, null); // uiData); 
                 // Do not attach bodyrowsCount to the first TBODY element, because of backward compatibility
                 writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext) + ":tbody_element" + 
                     (bodyrowsCount == 0 ? "" : bodyrowsCount), null);
@@ -622,10 +622,10 @@ public class HtmlTableRendererBase exten
         if (!isRowRendered)
         {
             //nothing to render, to get valid xhtml we render an empty dummy row
-            writer.startElement(HTML.TBODY_ELEM, uiData);
+            writer.startElement(HTML.TBODY_ELEM, null); // uiData);
             writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext) + ":tbody_element", null);
-            writer.startElement(HTML.TR_ELEM, uiData);
-            writer.startElement(HTML.TD_ELEM, uiData);
+            writer.startElement(HTML.TR_ELEM, null); // uiData);
+            writer.startElement(HTML.TD_ELEM, null); // uiData);
             writer.endElement(HTML.TD_ELEM);
             writer.endElement(HTML.TR_ELEM);
             writer.endElement(HTML.TBODY_ELEM);
@@ -674,12 +674,12 @@ public class HtmlTableRendererBase exten
         
         if(rowHeader) 
         {
-            writer.startElement(HTML.TH_ELEM, uiData);   
+            writer.startElement(HTML.TH_ELEM, null); // uiData);   
             writer.writeAttribute(HTML.SCOPE_ATTR, HTML.SCOPE_ROW_VALUE, null);
         }
         else 
         {
-            writer.startElement(HTML.TD_ELEM, uiData);
+            writer.startElement(HTML.TD_ELEM, null); // uiData);
         }
         if (styles.hasColumnStyle())
         {
@@ -710,7 +710,7 @@ public class HtmlTableRendererBase exten
         UIData uiData,
         Styles styles, int rowStyleIndex) throws IOException
     {
-        writer.startElement(HTML.TR_ELEM, uiData);
+        writer.startElement(HTML.TR_ELEM, null); // uiData);
         
         renderRowStyle(facesContext, writer, uiData, styles, rowStyleIndex);
         
@@ -958,7 +958,7 @@ public class HtmlTableRendererBase exten
             HtmlRendererUtils.writePrettyLineSeparator(facesContext);
             if (elemName != null)
             {
-                writer.startElement(elemName, component);
+                writer.startElement(elemName, null); // component);
             }
             if (header)
             {
@@ -1104,8 +1104,8 @@ public class HtmlTableRendererBase exten
             throws IOException
     {
         HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-        writer.startElement(HTML.TR_ELEM, component);
-        writer.startElement(colElementName, component);
+        writer.startElement(HTML.TR_ELEM, null); // component);
+        writer.startElement(colElementName, null); // component);
         if (colElementName.equals(determineHeaderCellTag(facesContext, component)) && isHeader)
         {
             writer.writeAttribute(HTML.SCOPE_ATTR, HTML.SCOPE_COLGROUP_VALUE, null);
@@ -1144,7 +1144,7 @@ public class HtmlTableRendererBase exten
     {
         HtmlRendererUtils.writePrettyLineSeparator(facesContext);
 
-        writer.startElement(HTML.TR_ELEM, component);
+        writer.startElement(HTML.TR_ELEM, null); // component);
         int columnIndex = 0;
         int newspaperColumns = getNewspaperColumns(component);
         for(int nc = 0; nc < newspaperColumns; nc++)
@@ -1193,7 +1193,7 @@ public class HtmlTableRendererBase exten
             return;
         }
          
-         writer.startElement(HTML.TD_ELEM, component);
+         writer.startElement(HTML.TD_ELEM, null); // component);
          //RendererUtils.renderChild(facesContext, spacer);
          spacer.encodeAll(facesContext);
          writer.endElement(HTML.TD_ELEM);
@@ -1289,7 +1289,7 @@ public class HtmlTableRendererBase exten
     protected void renderColumnHeaderCell(FacesContext facesContext, ResponseWriter writer, UIComponent uiComponent,
             UIComponent facet, String headerStyleClass, int colspan) throws IOException
     {
-        writer.startElement(determineHeaderCellTag(facesContext, uiComponent.getParent()), uiComponent);
+        writer.startElement(determineHeaderCellTag(facesContext, uiComponent.getParent()), null); // uiComponent);
         if (colspan > 1)
         {
             writer.writeAttribute(HTML.COLSPAN_ATTR, new Integer(colspan), null);
@@ -1344,7 +1344,7 @@ public class HtmlTableRendererBase exten
     protected void renderColumnFooterCell(FacesContext facesContext, ResponseWriter writer, UIComponent uiComponent,
         UIComponent facet, String footerStyleClass, int colspan) throws IOException
     {
-        writer.startElement(HTML.TD_ELEM, uiComponent);
+        writer.startElement(HTML.TD_ELEM, null); // uiComponent);
         if (colspan > 1)
         {
             writer.writeAttribute(HTML.COLSPAN_ATTR, new Integer(colspan), null);

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTextRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTextRendererBase.java?rev=1468656&r1=1468655&r2=1468656&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTextRendererBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlTextRendererBase.java Tue Apr 16 22:49:45 2013
@@ -194,11 +194,7 @@ public class HtmlTextRendererBase
         ResponseWriter writer = facesContext.getResponseWriter();
 
         String clientId = component.getClientId(facesContext);
-        String value = org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(facesContext, component);
-        if (log.isLoggable(Level.FINE))
-        {
-            log.fine("renderInput '" + value + "'");
-        }
+
         writer.startElement(HTML.INPUT_ELEM, component);
         writer.writeAttribute(HTML.ID_ATTR, clientId, null);
         writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
@@ -206,11 +202,8 @@ public class HtmlTextRendererBase
         //allow extending classes to modify html input element's type
         String inputHtmlType = getInputHtmlType(component);
         writer.writeAttribute(HTML.TYPE_ATTR, inputHtmlType, null);
-        
-        if (value != null)
-        {
-            writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR);
-        }
+
+        renderValue(facesContext, component, writer);
 
         Map<String, List<ClientBehavior>> behaviors = null;
         if (component instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(
@@ -285,7 +278,22 @@ public class HtmlTextRendererBase
             writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR);
         }
     }
-    
+
+    protected void renderValue(FacesContext facesContext, UIComponent component, ResponseWriter writer)
+            throws IOException
+    {
+        String value = RendererUtils.getStringValue(facesContext, component);
+        if (log.isLoggable(Level.FINE))
+        {
+           log.fine("renderInput '" + value + "'");
+        }
+
+        if (value != null)
+        {
+            writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR);
+        }
+    }
+
     protected void renderInputEnd(FacesContext facesContext, UIComponent component) throws IOException
     {
         ResponseWriter writer = facesContext.getResponseWriter(); 



Mime
View raw message