9 Replies Latest reply: May 25, 2012 10:03 AM by atarifreak73 RSS

    a4j:commandLink action on second click - again

    atarifreak73 Newbie

      I know, there exists by now many many threads and posts in many communitys, and I have reseachred many days, but I found not the accurate solution. I have reduced the problem to the following codelines:

       

      test_a.xhtml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!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:a4j="http://richfaces.org/a4j"
            xml:lang="en" lang="en"
            xmlns:h="http://java.sun.com/jsf/html">
      <h:head />
      <h:body>
          <h:form id="frm_a">
              <h:outputText value="= A =" />
              <h:panelGrid columns="1">
                  <h:column><a4j:commandLink action="to_c" execute="@this">
                      <h:outputText value="zu C" />
                  </a4j:commandLink></h:column>
                  <h:column><a4j:commandLink action="to_b" execute="@this">
                      <h:outputText value="zu B" />
                  </a4j:commandLink></h:column>
              </h:panelGrid>
          </h:form>
      </h:body>
      </html>
      
      

       

      2. Code:

      test_b.xhtml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!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:a4j="http://richfaces.org/a4j"
            xml:lang="en" lang="en"
            xmlns:h="http://java.sun.com/jsf/html">
      <h:head />
      <h:body>
          <h:form>
              <h:outputText value="= B =" />
              <h:panelGrid columns="1">
                  <h:column><a4j:commandLink action="to_c" execute="@this">
                      <h:outputText value="zu C" />
                  </a4j:commandLink></h:column>
                  <h:column><a4j:commandLink action="to_a" execute="@this">
                      <h:outputText value="zu A" />
                  </a4j:commandLink></h:column>
              </h:panelGrid>
          </h:form>
      </h:body>
      </html>
      

       

      test_c.xhtml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!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:a4j="http://richfaces.org/a4j"
            xml:lang="en" lang="en"
            xmlns:h="http://java.sun.com/jsf/html">
      <h:head />
      <h:body>
          <h:form>
              <h:outputText value="= C =" />
              <h:panelGrid columns="1">
                  <h:column><a4j:commandLink action="to_a" execute="@this">
                      <h:outputText value="zu A" />
                  </a4j:commandLink></h:column>
                  <h:column><a4j:commandLink action="to_b" execute="@this">
                      <h:outputText value="zu B" />
                  </a4j:commandLink></h:column>
              </h:panelGrid>
          </h:form>
      </h:body>
      </html>
      
      

       

      a part of faces-config.xml:

       

      ...   
      
      <navigation-rule>
              <from-view-id>/test_a.xhtml</from-view-id>
              <navigation-case>
                  <from-outcome>to_b</from-outcome>
                  <to-view-id>/test_b.xhtml</to-view-id>
              </navigation-case>
              <navigation-case>
                  <from-outcome>to_c</from-outcome>
                  <to-view-id>/test_c.xhtml</to-view-id>
              </navigation-case>
          </navigation-rule>
      
      ...

       

      When I click to the navigationlinks, sometimes I must click several times to navigate to the desired page. It´s also by using actions in the managed beans. The first click wood be mostly ignored, but not always.

      I´m using:
      - JBoss 6.1 (with included JSF 2.0.3)
      - Richfaces 4.2.2

       

      I´m so thankful for any solutions!

        • 1. Re: a4j:commandLink action on second click - again
          atarifreak73 Newbie

          The first click after the first Site works always.

           

          For instance I call the URL: http://localhost:8080/lm/test_a.jsf all navigationlinks from test_a.xhtml are working. But when I navigate along to B or C, then I have the problem with the second click.

          • 2. Re: a4j:commandLink action on second click - again
            atarifreak73 Newbie

            Have anyone a idea?

            Is it ambiguous what I mean?

             

            Thank You for any answers.

            • 3. Re: a4j:commandLink action on second click - again
              Stan Silvert Master

              Hi,

               

              I've moved your thread to the RichFaces forum.  I think you'll have better luck with a4j questions here.

               

              Stan

              • 4. Re: a4j:commandLink action on second click - again
                Brendan Healey Master

                In JSF 2 the navigation-rules in faces-config are optional as implicit navigation was introduced. You can just have

                action="test_a" and it will navigate to test_a.xhtml, with nothing added to faces-config. I'm not sure if this will

                help but it' worth a try, your code looks ok to me. What is the value of STATE_SAVING_METHOD in web.xml?

                 

                Also what is the scope of your backing bean? If you are using @RequestScoped can you try @ViewScoped?

                 

                Edit: what you're possibly seeing is that the page IS changing, but the URL in the browser window is one step

                behind. You can use action="test_a?faces-redirect=true".

                 

                Regards,

                Brendan.

                 

                See also: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183

                • 5. Re: a4j:commandLink action on second click - again
                  atarifreak73 Newbie

                  Thank You for your answer!

                   

                  I know, before I use the navigation-tules, I used the automatic navigation with the direct string "test_a". I thought, the navigation-rule solved the problem.

                   

                  The workarround with "faces-redirect=true" I haved tested, but this not fixed my problem.

                  The problem is, the content of the page changed on the second click. I have no preference, how the url looks. I have before used a managed bean with action-Methods, my original method. There I have also the problem, the actionmethod executed on the second click. My beans have sessionscope.

                   

                  The STATE_SAVING_METHOD I have switched to server or client with no difference.

                   

                  Here my web-xml:

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <web-app xmlns="http://java.sun.com/xml/ns/javaee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                             version="2.5">
                      <servlet>
                          <servlet-name>Faces Servlet</servlet-name>
                          <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                          <load-on-startup>1</load-on-startup>
                      </servlet>
                      <servlet-mapping>
                          <servlet-name>Faces Servlet</servlet-name>
                          <url-pattern>*.faces</url-pattern>
                          <url-pattern>*.jsf</url-pattern>
                      </servlet-mapping>
                      <context-param>
                          <param-name>facelets.SKIP_COMMENTS</param-name>
                          <param-value>true</param-value>
                      </context-param>
                      <context-param>
                          <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
                          <param-value>false</param-value>
                      </context-param>
                      <context-param>
                          <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                          <param-value>client</param-value>
                      </context-param>
                      <context-param>
                          <param-name>javax.faces.PROJECT_STAGE</param-name>
                          <param-value>Development</param-value>
                      </context-param>
                      <error-page>
                          <exception-type>javax.faces.application.ViewExpiredException</exception-type>
                          <location>/timeout.jsf?faces-redirect=true</location>
                      </error-page>
                  </web-app>
                  
                  
                  • 6. Re: a4j:commandLink action on second click - again
                    Brendan Healey Master

                    Hmmm, it's never easy is it. For webkit based browsers like chrome you need to use an f:view tag like this:

                     

                    ...

                    <f:view contentType="text/html">

                      <h:head>

                      </h:head>

                      <h:body>

                      </h:body>

                    </f:view>

                    ...

                     

                    Perhaps add a messages component - I don't see anything that would cause a validation error, although the

                    cursed 'nested form' error could be produced because you have PROJECT_STAGE set to Development, can

                    you try Production?

                     

                    <a4j:outputPanel ajaxRendered="true">

                      <h:messages/>

                    </a4j:outputPanel>

                     

                    Also, keep an eye out for any javascript errors in the browser javascript console. A real long shot and I'm not

                    sure if I'm imagining it or not, but deep in the recesses of my memory is the idea that I've seen a bug report

                    related to an empty h:head section, can you put something in there like:

                     

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

                     

                    My final suggestion would be to upgrade JSF, 2.1.8 is just out and there've been hundreds of fixes since 2.0.3.

                     

                    Regards,

                    Brendan.

                    • 7. Re: a4j:commandLink action on second click - again
                      atarifreak73 Newbie

                      The source for a (the others are similar):

                       

                      <?xml version="1.0" encoding="UTF-8"?>
                      <!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:a4j="http://richfaces.org/a4j" xmlns:f="http://java.sun.com/jsf/core"
                            xml:lang="en" lang="en"
                            xmlns:h="http://java.sun.com/jsf/html">
                      <f:view contentType="text/html">
                      <h:head>
                          <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
                      </h:head>
                      <h:body>
                          <h:form id="frm_a">
                              <h:outputText value="= A =" />
                              <h:panelGrid columns="1">
                                  <h:column><a4j:commandLink action="to_c" execute="@this">
                                      <h:outputText value="zu C" />
                                  </a4j:commandLink></h:column>
                                  <h:column><a4j:commandLink action="to_b" execute="@this">
                                      <h:outputText value="zu B" />
                                  </a4j:commandLink></h:column>
                              </h:panelGrid>
                              <a4j:outputPanel ajaxRendered="true">
                                  <h:messages />
                              </a4j:outputPanel>
                          </h:form>
                      </h:body>
                      </f:view>
                      </html>
                      
                      

                       

                      I have upgraded to JSF 2.1.8 with no other result. (Is it enough to integrate the javax.faces-2.1.8.jar in WEB-INF\lib?) I have switched to JBoss 5.1, it´s the same.

                      I have testet with h:commandLink, and it runs perfecty, but I need a4j:commandLink

                      When I use a4j:commandLink in mix with h:commandLinks in

                       

                      my Projects, also the h:commandLinks sometimes response on second click.

                       

                      I suppose, there is anywhere an error, probable a simple error, but I can find them!

                      • 8. Re: a4j:commandLink action on second click - again
                        Brendan Healey Master

                        I'm a glassfish user so unable to comment on Jboss AS. Perhaps worth posting a summary of this in www.stackoverflow.com

                        and make sure you tag the question with JSF, and perhaps include the text "@BalusC".

                        • 9. Re: a4j:commandLink action on second click - again
                          atarifreak73 Newbie

                          Anyway thank You for Your effort

                           

                          I think, a4j:commandLink is improper to use as Navigationlink. My problem is, my links must be all in one: In case of the action, they must navigate to another page or produce a popup for detailquestions (and then navigate to another page) with ajax content.

                          In the moment it works, but I dont know, what I can do, when this problem comes again.

                           

                          In richfaces absence a attribute, in this I can say ambiguous, what the returned value is, either a id for rendering or a jsf-page. In the second case the a4j:commandLink will works as h:commandLink. At the moment it could be a problem, when a a4j:commandLink works outside his form.