Uploaded image for project: 'RichFaces'
  1. RichFaces
  2. RF-13018

a4j:commandButton wrong actions performed

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 4.2.3.Final, 4.3.2
    • Fix Version/s: 4.3.8, 4.5.0.Alpha3, 5.0.0.Alpha4
    • Component/s: component-a4j-core
    • Labels:
    • Environment:

      Server: Fedora 17, Jboss AS 7.1.1.Final, Jboss EAP 6.1.0.Beta, Java 1.7.0_15
      Browsers: Chrome 26 and Chrome 27 on (Linux & Windows 7), Firefox 20.0 (Linux & Windows 7), IE 9

    • Steps to Reproduce:
      Hide

      Create a project using the maven archetype: org.richfaces.archetypes, richfaces-archetype-simpleapp.

      Change RichBean.java to:

      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 "";
          }
      }
      
      

      Change index.xhtml to:

      <!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>
      
      

      Run and press the buttons and watch the console output. Pressing either button will result in both actions being fired.

      Show
      Create a project using the maven archetype: org.richfaces.archetypes, richfaces-archetype-simpleapp. Change RichBean.java to: 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 ""; } } Change index.xhtml to: <!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> Run and press the buttons and watch the console output. Pressing either button will result in both actions being fired.
    • Workaround Description:
      Hide

      Don't use type='button'

      Show
      Don't use type='button'

      Description

      When an a4j commponent (a4j:commandButton, a4j:jsFunction) is activated, actions of other a4j:commandButtons on the page with type=button will be fired.

      For example, pressing either button in the following code will cause both richBean.function1() and richBean.function2() actions.

      <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>
      

      Note, if one of the a4j:commandButton is marked immediate, then only one action (possibly the wrong action) will be performed and block others. For instance if an a4j:jsFunction action was being triggered, the a4j:commandButton action may occur making appear that the a4j:jsFunction failed.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  michpetrov Michal Petrov
                  Reporter:
                  rhare2 Rob Hare
                • Votes:
                  2 Vote for this issue
                  Watchers:
                  9 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Time Tracking

                    Estimated:
                    Original Estimate - 2 hours
                    2h
                    Remaining:
                    Remaining Estimate - 2 hours
                    2h
                    Logged:
                    Time Spent - Not Specified
                    Not Specified