11 Replies Latest reply on Dec 1, 2014 11:39 AM by kevin 2

    a4j:commandButton - pressing button fires all a4j:commandButton actions on the page

    Rob Hare Newbie

      This seems so broken that I have to believe I'm doing somthing wrong, but it's also incredibly simple. I have 2 a4j:commandButtons on the same page.  No matter which button I press both actions are fired.

       

       

      I started with a maven archetype project in eclipse: org.richfaces.archetypes, richfaces-archetype-simpleapp.  Then changed RichBean to have 2 functions.

       

      import java.io.Serializable;

      import javax.faces.bean.ManagedBean;

      import javax.faces.bean.ViewScoped;

       

      @ViewScoped

      @ManagedBean

      public class RichBean implements Serializable {

       

          private static final long serialVersionUID = -6239437588285327644L;

       

          public String function1() {

                    System.out.println("Function 1 called");

              return "";

          }

         

          public String function2() {

                    System.out.println("Function 2 called");

              return "";

          }

      }

       

       

      and changed index.xhtml to have 2 buttons.

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"

          xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j">

       

          <h:head>

            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

            <title>Test</title>

         </h:head>

         

          <h:body>

              <h:form id="testForm">

                  <a4j:commandButton id="button1" type="button" value="Button 1"

                                action="#{richBean.function1}" />            

                   <a4j:commandButton id="button2" type="button" value="Button 2"

                                action="#{richBean.function2}" />    

              </h:form>

          </h:body>

      </html>

       

      when I run this under Jboss AS 7.1.1.Final or Jboss EAP 6.1.0.Beta I get the same result.  Pressing either button results in both functions being called.  Is this broken or am I doing something incredibly stupid?

       

      Thanks, this is driving me nuts...

        • 2. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
          Lukáš Fryč Master

          Hey Rob,

           

          could you post details of a request headers and a response text (XML with <partial-response>) as observed in Chrome Dev Tools / Firebug or any other Network inspecting tool?

           

          Note: as issue report states, this affects 4.2.3 and 4.3.2 as well

          • 3. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
            Rob Hare Newbie

            Lukáš Fryč wrote:

             

            Hey Rob,

             

            could you post details of a request headers and a response text (XML with <partial-response>) as observed in Chrome Dev Tools / Firebug or any other Network inspecting tool?

             

             

            From Chrome Dev Tools.

             

            Request Headers:

            Accept:*/*
            Accept-Encoding:gzip,deflate,sdch
            Accept-Language:en-US,en;q=0.8
            Connection:keep-alive
            Content-Length:462
            Content-type:application/x-www-form-urlencoded;charset=UTF-8
            Cookie:JSESSIONID=UTjNTjzDiLc-X5pTXK1E3AUm.undefined
            Faces-Request:partial/ajax
            Host:localhost:8080
            Origin:http://localhost:8080
            Referer:http://localhost:8080/button/
            User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36

             

            Form Data:

            testForm:testForm
            testForm:button1:Button 1
            testForm:button2:Button 2
            javax.faces.ViewState:5007719877964413075:2892067377465562569
            javax.faces.source:testForm:button1
            javax.faces.partial.event:click
            javax.faces.partial.execute:testForm:button1 @component
            javax.faces.partial.render:@component
            org.richfaces.ajax.component:testForm:button1
            testForm:button1:testForm:button1
            rfExt:null
            AJAX:EVENTS_COUNT:1
            javax.faces.partial.ajax:true
            Response Headersview source

             

            Response:

            <?xml version='1.0' encoding='UTF-8'?>

            <partial-response><changes><update id="javax.faces.ViewState"><![CDATA[5007719877964413075:2892067377465562569]]></update></changes></partial-response>

             

             

            Note: as issue report states, this affects 4.2.3 and 4.3.2 as well

             

            Yep, I tried it under both to make sure it wasn't fixed in a newer release than what I was using at the time I ran into this issue.

             

            If you need anything else just let me know.

            • 4. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
              Rob Hare Newbie

              A little more background:

               

              I came across this when I had a a4j:commandButton on the same page as a a4j:jsFunction.   For some reason the a4j:jsFunction stopped working and once I dug into it I discovered that I was seeing the a4j:commandButton action fired instead of that on the a4j:jsFunction.  I started trying to make a much simpler case than what I had in my code, which is when I got down to the example above.   In my case because the a4j:commandButton was marked immediate, only it was fired and not all the actions.  If you change one of the buttons to type=submit, the problem goes away.  Likewise intermediate will also change the behavior, you might only get the wrong action fired as opposed to all of them.

               

              My original application code broke on Chrome 27, not Chrome 26. It looks like Chrome 27 passed all the buttons in the form data, and it didn't in Chrome 26.  Not sure if this is part of the problem but it's what led me to the simple case.

              • 5. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                Lukáš Fryč Master

                I know you are using JBoss AS 7.1.1.Final / EAP 6.1.0.Beta1 - by any chance, aren't you using non-default versions of Mojarra?

                 

                Or rather: what versions of Mojarra your app run with?

                • 6. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                  Lukáš Fryč Master

                  ah, so your issue can be reproduced only on Chrome 27? could you eventually try other browsers?

                  • 7. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                    Rob Hare Newbie

                    Lukáš Fryč wrote:

                     

                    I know you are using JBoss AS 7.1.1.Final / EAP 6.1.0.Beta1 - by any chance, aren't you using non-default versions of Mojarra?

                     

                    Or rather: what versions of Mojarra your app run with?

                     

                    Just out of the box Jboss AS 7.1.1.Final and EAP 6.1.0.Beta1  which means Mojarra 2.1.7-jbossorg-1 and Mojarra 2.1.19-jboss
                    org-1 respectively.

                     

                    Lukáš Fryč wrote:

                     

                    ah, so your issue can be reproduced only on Chrome 27? could you eventually try other browsers?

                     

                    No, the problem is on many browsers.  Sorry, I I wasn't very clear in my last post.  What I was trying to say is that something changed in Chrome 27 that brought the problem to light in what appears to be including all the buttons in the form data.  However, it was just an exacerbating condition.   Once I started trying to make a simple example (the one in the original post), it occurs on all the following broswers:

                     

                    • Fedora 17, Chrome 27.0.1453.93
                    • Fedora 17, Firefox 20.0
                    • Fedora 16, Firefox 18.0.2
                    • Fedora 16, Chrome 26.0.14.10.63
                    • Windows 7, Chrome 26.0.1410.64 m
                    • Windows 7, IE 9.0.8112.16421
                    • Windows 7, Firefox 20.0.1
                    • Android 4.2.2. Chrome 18.0.1025469

                     

                    Are you able to duplicate the issue?  I'm assuming that having both actions fire is not the expected behavior?

                    I put exactly how using Eclipse I created the application in the JIRA entry.

                     


                    • 8. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                      Lukáš Fryč Master

                      Rob, could you confirm in the JIRA that when you remove @type, then the issue disappears?

                      • 9. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                        Rob Hare Newbie

                        Lukáš Fryč wrote:

                         

                        Rob, could you confirm in the JIRA that when you remove @type, then the issue disappears?

                         

                        I did confirm that if the buttons are of type="submit" then it does not occur and added a comment to JIRA.

                         

                        However, that is not an easy workaround because on a form with text fields, hitting return will cause the first button labeled "submit" to be activated.  Hence the reason you want type="button" on all buttons except 1 which is type=submit.  If you change all to type="submit" then hitting return within a text field will cause the first button on the page to be activated, possibly not what was intended. The work around will require playing games with either CSS or javascript to cause the right button to appear first on the page to fix a new problem caused by the workaround.  UGH!

                        • 10. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                          Brian Leathem Master

                          If you want to experiment a bit, you can try the commandButton from the RichFaces bootstrap sandbox project.  It has explicit support for type=button:

                          https://bootstrap-richfaces.rhcloud.com/component/commandButton/index.jsf

                           

                          This is likely how we will move forward with the commandButton in RF 5, it would be good to get some feedback if it resolves your problem.

                           

                          Brian

                          • 11. Re: a4j:commandButton - pressing button fires all a4j:commandButton actions on the page
                            kevin 2 Newbie

                            Hello,

                             

                            Does this bug affect the 4.3.7 version ?

                             

                            I'm having a similar issue using h:commandLink with a4j:param (for downloading file).

                             

                            My code is :

                            <rich:dataTable value="#{dataBean.dataList}" var="entry">
                              ...
                              <h:column>
                                <h:commandLink title="Download" action="#{dataBean.download}" immediate="true">
                                  <a4j:param value="#{entry.id}" assignTo="#{dataBean.selectedId}" />
                                  <img src="#{resource['download_img']}" />
                                </h:commandLink>
                              </h:column>
                            </rich:dataTable>
                            
                            
                            

                             

                            When I click on the button, I got a NPE in :

                            
                            
                            
                            org.richfaces.renderkit.AjaxCommandRendererBase.isSubmitted(FacesContext, UIComponent) line: 83
                            
                            
                            
                            
                            
                            
                            

                             

                            Is there a workaround ?

                             

                            EDIT :

                            Finally it went OK using the workaround described in the bug RF-13018.

                            But I had to replace all type="button" by type="submit" for each a4j:commandButton in the project.

                             

                            Thanks