6 Replies Latest reply on May 3, 2012 2:07 PM by arkhalil

    a4j:commandLink doesn’t reacts at first click

    arkhalil

      Hi Everyone,

       

      1. Aajax call from header menu (a4:commandLink) loads a panel which contains a form named form1.

      2. First click on a4j:commandLink within form1:

          - ajax request is received on server but it doesn't invoke action method)

      3. Subsequent clicks are working fine.

       

      My understanding:  The problem is with it form. The reason being this form is loaded as result of ajax call. If I add this form directly in the page then it is working fine.

       

      Can anyone guide? Thanks.

        • 1. Re: a4j:commandLink doesn’t reacts at first click
          healeyb

          It would be helpful to see the code, what kind of panel is it, a popupPanel? if so there are a couple of possible fixes.

          • 2. Re: a4j:commandLink doesn’t reacts at first click
            arkhalil

            You can see the sample code as an example:

             

            ................................................................................

            <ui:composition xmlns="http://www.w3.org/1999/xhtml"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:f="http://java.sun.com/jsf/core"

                xmlns:rich="http://richfaces.org/rich"

                xmlns:ui="http://java.sun.com/jsf/facelets"

                xmlns:a4j="http://richfaces.org/a4j">

             

                 <h:form id="menuform">

                           <a4j:commandLink value="News" action="#{menueController.loadNewsList()}" render="bodyPanel"/>

                 </h:form>

             

                 <a4j:outputPanel id="bodyPanel">

                           <h:form id="newsform">

                           <a4j:commandLink value="More Info" action="#{newsController.loadNewsDetail()}" render="newsDetailPanel"/>

                           </h:form>

                           <a4j:outputPanel id="newsDetailPanel">

                                <h:outputText value="#{newsBean.detail}" />

                           </a4j:outputPanel>

                 </a4j:outputPanel>

            </ui:composition>

            ................................................................................

             

            Thanks.

            • 3. Re: a4j:commandLink doesn’t reacts at first click
              healeyb

              The problem is with the multiple forms. It's easily fixed by removing newsform and extending menuform to wrap

              the lower outputPanel. Why is it happening? there is a mojarra jira about this but java.net is still down so I can't

              find it, but I remember it's something to do with the viewState.

               

              With the use of ajax and the ability to control what gets submitted to the server with execute= I personally feel

              that there's a good argument for using a single form per page (except in rare circumstances such as some file

              upload and dialog box implementations), and you don't get caught by easy-to-forget naming container mishaps,

              and problems such as this one.

               

              Regards,

              Brendan.

              • 4. Re: a4j:commandLink doesn’t reacts at first click
                arkhalil

                Yes, That sounds good. Thanks for guiding.

                • 5. Re: a4j:commandLink doesn’t reacts at first click
                  healeyb

                  Ok, java.net is back again. I'm reasonably sure you're hitting this limitation: http://java.net/jira/browse/JAVASERVERFACES-1718,

                  because you have a form (newsform) nested within an ajax target (bodyPanel) where the request originates from another form

                  (menuform).

                   

                  The issue has been closed and this is being treated as a spec issue: http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1024,

                  so please vote for it if you want it fixed.

                   

                  Note that there is a workaround given in the -1718 bug report if you can live with editing jsf.js.

                   

                  Regards,

                  Brendan.

                  • 6. Re: a4j:commandLink doesn’t reacts at first click
                    arkhalil

                    Yes, You are right. But I resolved my issue using a4j:jsFunction in the following way for the time being:

                     

                    ................................................................................

                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"

                        xmlns:h="http://java.sun.com/jsf/html"

                        xmlns:f="http://java.sun.com/jsf/core"

                        xmlns:rich="http://richfaces.org/rich"

                        xmlns:ui="http://java.sun.com/jsf/facelets"

                        xmlns:a4j="http://richfaces.org/a4j">

                     

                         <h:form id="menuform">

                                   <a4j:commandLink value="News" action="#{menueController.loadNewsList()}" render="bodyPanel"/>

                                  

                                   <a4j:jsFunction name="loadNewsDetailJsFunction" action="#{newsController.loadNewsDetail()}" render="newsDetailPanel">

                                   </a4j:jsFunction>

                         </h:form>

                     

                         <a4j:outputPanel id="bodyPanel">

                                  

                                   <a href="#" onclick="loadNewsDetailJsFunction();">More Info</a>

                                  

                                   <a4j:outputPanel id="newsDetailPanel">

                                        <h:outputText value="#{newsBean.detail}" />

                                   </a4j:outputPanel>

                         </a4j:outputPanel>

                    </ui:composition>

                    ................................................

                     

                    Brendan, Thank you very much for bringing a very common JSF issue in notice.

                    1 of 1 people found this helpful