javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-1451

RenderKitUtils renders either "action" or "click" behaviors, not both

    Details

    • Type: Improvement Improvement
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.2, 2.1.17
    • Fix Version/s: None
    • Component/s: renderkit
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,451
    • Status Whiteboard:
      Hide

      size_medium importance_medium

      Show
      size_medium importance_medium
    • Tags:

      Description

      The renderOnClick method of RenderKitUtils in 2.0.2 checks to see if there are
      any "click" client behaviors, if so, it renders their JS, if not, it renders the
      JS for any "action" client behaviors. I believe this should not be either/or,
      but both. If there are action and click event client behaviors present, both
      should encoded. The same is true for the valueChange/change for input
      components, both should be encoded, not one or the other.

      So with this code:
      <f:ajax event="action">
      <h:commandButton>
      <my:custombehavior event="click" />
      </h:commandButton>
      <f:ajax/>

      I would expect that my custombehavior would be called, then as long as that does
      not return false, the form would be submitted via ajax.

        Activity

        Hide
        arjan tijms added a comment -

        Everything in the specification leads the reader to believe that this is a bug in the implementation

        Just curious, but have you tried how MyFaces behaves here?

        Show
        arjan tijms added a comment - Everything in the specification leads the reader to believe that this is a bug in the implementation Just curious, but have you tried how MyFaces behaves here?
        Hide
        arobinson added a comment -

        It appears to have implemented it correctly. I did not run any code to verify it, but I did take a quick look through their code and it seems to have everything to append both the click and action client behaviors into the onclick when both are present.

        The HtmlButtonRendererBase.encodeBegin calls HtmlRendererUtils.buildBehaviorChain with two different actions (click and action) and uses both to render the client scripts.

        org.apache.myfaces.shared.renderkit.html.HtmlButtonRendererBase.encodeBegin
                        String onClick = HtmlRendererUtils.buildBehaviorChain(facesContext, uiComponent,
                                ClientBehaviorEvents.CLICK, paramList, ClientBehaviorEvents.ACTION, paramList, behaviors,
                                commandOnclick , null);
                        if (onClick.length() != 0)
                        {
                            writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
                        }
        
        HtmlRendererUtils.buildBehaviorChain
                boolean submitting1 = getClientBehaviorScript(facesContext,
                        uiComponent, targetClientId, eventName1, clientBehaviors,
                        behaviorCode, params);
                ScriptContext behaviorCode2 = new ScriptContext();
                boolean submitting2 = getClientBehaviorScript(facesContext,
                        uiComponent, targetClientId, eventName2, clientBehaviors,
                        behaviorCode2, params2);
        
                // ClientBehaviors for both events have to be checked for the Submitting hint
                boolean submitting = submitting1 || submitting2;
                if (behaviorCode != null
                        && !behaviorCode.toString().trim().equals(STR_EMPTY))
                {
                    finalParams.add(behaviorCode.toString());
                }
                if (behaviorCode2 != null
                        && !behaviorCode2.toString().trim().equals(STR_EMPTY))
                {
                    finalParams.add(behaviorCode2.toString());
                }
                if (serverEventCode != null
                        && !serverEventCode.trim().equals(STR_EMPTY))
                {
                    finalParams.add('\'' + escapeJavaScriptForChain(serverEventCode) + '\'');
                }
        
        Show
        arobinson added a comment - It appears to have implemented it correctly. I did not run any code to verify it, but I did take a quick look through their code and it seems to have everything to append both the click and action client behaviors into the onclick when both are present. The HtmlButtonRendererBase.encodeBegin calls HtmlRendererUtils.buildBehaviorChain with two different actions (click and action) and uses both to render the client scripts. org.apache.myfaces.shared.renderkit.html.HtmlButtonRendererBase.encodeBegin String onClick = HtmlRendererUtils.buildBehaviorChain(facesContext, uiComponent, ClientBehaviorEvents.CLICK, paramList, ClientBehaviorEvents.ACTION, paramList, behaviors, commandOnclick , null ); if (onClick.length() != 0) { writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null ); } HtmlRendererUtils.buildBehaviorChain boolean submitting1 = getClientBehaviorScript(facesContext, uiComponent, targetClientId, eventName1, clientBehaviors, behaviorCode, params); ScriptContext behaviorCode2 = new ScriptContext(); boolean submitting2 = getClientBehaviorScript(facesContext, uiComponent, targetClientId, eventName2, clientBehaviors, behaviorCode2, params2); // ClientBehaviors for both events have to be checked for the Submitting hint boolean submitting = submitting1 || submitting2; if (behaviorCode != null && !behaviorCode.toString().trim().equals(STR_EMPTY)) { finalParams.add(behaviorCode.toString()); } if (behaviorCode2 != null && !behaviorCode2.toString().trim().equals(STR_EMPTY)) { finalParams.add(behaviorCode2.toString()); } if (serverEventCode != null && !serverEventCode.trim().equals(STR_EMPTY)) { finalParams.add('\'' + escapeJavaScriptForChain(serverEventCode) + '\''); }
        Hide
        ren.zhijun.oracle added a comment -

        Hi Zhijun,

        Changebundle looks good.

        OK now for some book keeping.

        1. Please open a BugDB tracking this work as this is an ADF issue.
        2. Use "BugDB #xxxx / JAVASERVERFACES-1451" in your commit message
        3. Please only commit this to trunk and wait for feedback to see if they are interested in a backport (because this is a really old issue and unless specifically asked to backport we should not backport it).

        Great work!

        Thanks!

        Kind regards,
        Manfred Riem

        Show
        ren.zhijun.oracle added a comment - Hi Zhijun, Changebundle looks good. OK now for some book keeping. 1. Please open a BugDB tracking this work as this is an ADF issue. 2. Use "BugDB #xxxx / JAVASERVERFACES-1451 " in your commit message 3. Please only commit this to trunk and wait for feedback to see if they are interested in a backport (because this is a really old issue and unless specifically asked to backport we should not backport it). Great work! Thanks! Kind regards, Manfred Riem
        Hide
        ren.zhijun.oracle added a comment -

        Code committed:

        rzhijun-mac:trunk zhijun$ svn commit -m "Bug#21132996 / JAVASERVERFACES-1451: RenderKitUtils renders either action or click behaviors, not both" --username ren.zhijun.oracle
        Sending jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
        Sending test/javaee6web/facelets
        Adding test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java
        Adding test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java
        Adding test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml
        Sending test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml
        Adding test/javaee6web/facelets/src/main/webapp/issue1451.xhtml
        Adding test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java
        Transmitting file data .......
        Committed revision 14772.

        Show
        ren.zhijun.oracle added a comment - Code committed: rzhijun-mac:trunk zhijun$ svn commit -m "Bug#21132996 / JAVASERVERFACES-1451 : RenderKitUtils renders either action or click behaviors, not both" --username ren.zhijun.oracle Sending jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java Sending test/javaee6web/facelets Adding test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java Adding test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java Adding test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml Sending test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml Adding test/javaee6web/facelets/src/main/webapp/issue1451.xhtml Adding test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java Transmitting file data ....... Committed revision 14772.
        Hide
        Ed Burns added a comment -

        JAVASERVERFACES-1451

        M test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java
        M test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java
        M test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java
        M test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml
        M test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml
        M test/javaee6web/facelets/src/main/webapp/issue1451.xhtml
        M jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java

        • Revert due to hudson failures
          Sending jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java
          Deleting test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java
          Deleting test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java
          Deleting test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml
          Sending test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml
          Deleting test/javaee6web/facelets/src/main/webapp/issue1451.xhtml
          Deleting test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java
          Transmitting file data ..
          Committed revision 14773.
        Show
        Ed Burns added a comment - JAVASERVERFACES-1451 M test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java M test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java M test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java M test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml M test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml M test/javaee6web/facelets/src/main/webapp/issue1451.xhtml M jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java Revert due to hudson failures Sending jsf-ri/src/main/java/com/sun/faces/renderkit/RenderKitUtils.java Deleting test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior.java Deleting test/javaee6web/facelets/src/main/java/com/sun/faces/test/javaee6web/facelets/CustomBehavior2.java Deleting test/javaee6web/facelets/src/main/webapp/WEB-INF/my.taglib.xml Sending test/javaee6web/facelets/src/main/webapp/WEB-INF/web.xml Deleting test/javaee6web/facelets/src/main/webapp/issue1451.xhtml Deleting test/javaee6web/facelets/src/test/java/com/sun/faces/test/javaee6web/facelets/Issue1451IT.java Transmitting file data .. Committed revision 14773.

          People

          • Assignee:
            ren.zhijun.oracle
            Reporter:
            arobinson74
          • Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated: