8 Replies Latest reply on Aug 5, 2012 2:56 AM by navurinv

    a4j:commandButton does nothing on first click, works on second click

    mark.robinson

      I have two pages where users can switch back and forth.  What happens is that I have to click the button twice to get the page to actually transition.  The problem goes away if I replace a4j:commandButton with an h:commandButton.  Am I doing something wrong with the a4j:commandButton?

       

      <f:view xmlns:util="http://java.sun.com/jsf/composite/banner" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"

              xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">

        <html xmlns="http://www.w3.org/1999/xhtml">

          <h:head>

            <title>login</title>

          </h:head>

          <h:body>

            <h:form id="regForm">

              <util:banner/>

              <h:outputLabel value="Registration"/>

              <h:panelGrid columns="2">

                <a4j:commandButton value="Existing user?" action="login"/>

              </h:panelGrid>

            </h:form>

          </h:body>

        </html>

      </f:view>

       

      and

       

      <f:view xmlns:util="http://java.sun.com/jsf/composite/banner" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"

              xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">

        <html xmlns="http://www.w3.org/1999/xhtml">

          <h:head>

            <title>login</title>

          </h:head>

          <h:body>

            <h:form id="loginForm">

                <a4j:commandButton value="Not an existing user?" action="registration"/>

              </h:panelGrid>

            </h:form>

          </h:body>

        </html>

      </f:view>

        • 1. Re: a4j:commandButton does nothing on first click, works on second click
          blabno

          What version fo RF?

          Is navigation triggered by navigation rules in faces-config? If so show it.

          • 2. Re: a4j:commandButton does nothing on first click, works on second click
            mark.robinson

            Hi Bernard,

             

            This is RF 4.1 and the navigation is done rules in faces-config.

             

              <navigation-rule>

                <from-view-id>/login.jsf</from-view-id>

                <navigation-case>

                  <from-outcome>registration</from-outcome>

                  <to-view-id>/registration.jsf</to-view-id>

                </navigation-case>

              </navigation-rule> 

              <navigation-rule>
                <from-view-id>/registration.jsf</from-view-id>
                <navigation-case>
                  <from-outcome>login</from-outcome>
                  <to-view-id>/login.jsf</to-view-id>
                </navigation-case>
              </navigation-rule>

            • 3. Re: a4j:commandButton does nothing on first click, works on second click
              blabno

              Shouldn't page id in from-view-id and to-view-id be with ".xhtml" extension?

               

              I've had problem with double click when I was rerendering the entire form (or component surrounding form) from other form.

              • 4. Re: a4j:commandButton does nothing on first click, works on second click
                mark.robinson

                I don't think it should be .xhtml, the files are named .jsf.  I did try switching it to .xhtml, it worked but the issues remained.

                 

                How did you solve the issue with double click on multiple forms?  I think it might be related.

                • 5. Re: a4j:commandButton does nothing on first click, works on second click
                  blabno

                  You just don't re-render forms or their parents from outside of them. What I do is to put some component like h:panelGroup (make sure it renders on page by giving it an id or styleClass) inside the form and nest all other form contents in it. Then I re-render only that h:panelGroup instead of form. That's it. It's a bug in JSF 2.0 (and probably 2.1) specification and this is the dummy workaround but we've got to live with it.

                  • 6. Re: a4j:commandButton does nothing on first click, works on second click
                    alv21

                    Bernard Labno ha scritto:

                     

                    You just don't re-render forms or their parents from outside of them. What I do is to put some component like h:panelGroup (make sure it renders on page by giving it an id or styleClass) inside the form and nest all other form contents in it. Then I re-render only that h:panelGroup instead of form. That's it. It's a bug in JSF 2.0 (and probably 2.1) specification and this is the dummy workaround but we've got to live with it.

                     

                    finally this is what I need to know and it solved my problems after 3 hours! (using jsf2 and richfaces4)

                    but I used <a4j:outputPanel instead h:panelGroup

                     

                    thanks

                    • 7. Re: a4j:commandButton does nothing on first click, works on second click
                      healeyb

                      Perhaps worth noting that JSF 2 has implicit navigation so you can just have <h:commandButton action="login" and it will try

                      to navigate to login.xhtml (or whatever default suffix is) with nothing in faces-config. I tried your code (minus the composite

                      component) including the nav rules in faces-config and it worked first time every time for me, which made me wonder if there

                      might be another factor involved which we've not considered yet. What state saving are you using in web.xml, and are you

                      using prefix or suffix mapping for FacesServlet?

                       

                      It's also never a bad idea to make sure that there are no javascript errors by running with the javascript console from your

                      browser/developer tools/error console (whichever).

                      • 8. Re: a4j:commandButton does nothing on first click, works on second click
                        navurinv

                        please use  execute attribute it may solve your problem