1 2 Previous Next 19 Replies Latest reply on Jul 26, 2007 5:21 AM by Alexander Jiteg

    Ajax4JSF eating my first two mouse clicks?

    Mike Maurer Newbie

      I am brand new to Ajax4JSF. My first test was to create a simple JSF page with four checkboxes and an outputText that displays how many of the boxes are checked. I use <a4j:support event="onclick" reRender="count"/> on each checkbox to cause the count to be rerendered. This works fine, but not until the third mouse click! With the first two clicks I check two of the boxes, but the count doesn't update. When I check the third box then the count rerenders like it should, and everything works great from then on. No matter which checkboxes are clicked on first, it doesn't update the count until the 3rd click. It's like the first two clicks are being eaten or ignored by the onclick event handler. What gives?

      Here is my code:

      JSF PAGE:

      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <html>
      
       <head>
       <title>Ajax Test</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       </head>
      
       <body>
      
       <f:view>
      
       <h:form>
      
       <h:selectBooleanCheckbox id="checkbox1" value="#{testAjaxBean.checkbox1}">
       <a4j:support event="onclick" reRender="count"/>
       </h:selectBooleanCheckbox>
       <h:selectBooleanCheckbox id="checkbox2" value="#{testAjaxBean.checkbox2}">
       <a4j:support event="onclick" reRender="count"/>
       </h:selectBooleanCheckbox>
       <h:selectBooleanCheckbox id="checkbox3" value="#{testAjaxBean.checkbox3}">
       <a4j:support event="onclick" reRender="count"/>
       </h:selectBooleanCheckbox>
       <h:selectBooleanCheckbox id="checkbox4" value="#{testAjaxBean.checkbox4}">
       <a4j:support event="onclick" reRender="count"/>
       </h:selectBooleanCheckbox>
      
       <h:outputText value="Count = #{testAjaxBean.totalCountChecked}" id="count"/>
      
       </h:form>
      
       </f:view>
      
       </body>
      
      </html>
      


      BEAN:
      public class TestAjaxBean
      {
       private boolean mCheckbox1;
       private boolean mCheckbox2;
       private boolean mCheckbox3;
       private boolean mCheckbox4;
      
       public boolean getCheckbox1()
       {
       return mCheckbox1;
       }
      
       public void setCheckbox1( boolean pVal )
       {
       mCheckbox1 = pVal;
       }
      
       public boolean getCheckbox2()
       {
       return mCheckbox2;
       }
      
       public void setCheckbox2( boolean pVal )
       {
       mCheckbox2 = pVal;
       }
      
       public boolean getCheckbox3()
       {
       return mCheckbox3;
       }
      
       public void setCheckbox3( boolean pVal )
       {
       mCheckbox3 = pVal;
       }
      
       public boolean getCheckbox4()
       {
       return mCheckbox4;
       }
      
       public void setCheckbox4( boolean pVal )
       {
       mCheckbox4 = pVal;
       }
      
       public int getTotalCountChecked()
       {
       int count = 0;
       if ( mCheckbox1 ) count++;
       if ( mCheckbox2 ) count++;
       if ( mCheckbox3 ) count++;
       if ( mCheckbox4 ) count++;
       return count;
       }
      }
      


        1 2 Previous Next