2 Replies Latest reply on Oct 29, 2010 2:01 PM by exosys

    AJaX problems

    exosys

      Dear friends, I ask for your help, please!
      I am trying to run a JSFUnit test which works perfectly, but not for AJAX events. In other words, when I click any "h:commandButton" everything goes well, but when I click one "a4j:commandButton" it just stops working. I have noticed that the execution gets locked at the com.gargoylesoftware.htmlunit.javascript.JavascriptEngine class. More precisely, inside of its internal class (HtmlUnitContextAction), at the "public final Object run(final Context cx)" method. Even more precisely, it gets locked at the first line of the following code:

       

                      synchronized (htmlPage_) { // 2 scripts can't be executed in parallel for one page
                          final Object response = doRun(cx);
                          doProcessPostponedActions();
                          return response;
                      }

       

      After that, I created a lower level version, I mean, I used HTMLUnit instead of JSFUnit. I changed from one single JSFUnit click to the following:

       

              HtmlInput btnProc = (HtmlInput) page3.getElementById("button_ID");
              final HtmlPage page4 = btnProc.click();
              System.out.print(page4.asXml());
              page4.refresh();

       

      In the third statement, the following page is printed:

       

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <html xmlns="http://www.w3.org/1999/xhtml"/>

       


      This is not the output expected. At this point it is clear that something wenty wrong. Finally, in the fourth line of the HTMLUnit code (page4.refresh), my test gets locked exactly like I described above, with JSFUnit. So, I think the locking itself is just a consequence of the "empty" page printed. No exception occurs at any time.
      These errors occur with my tests only. If I run the same sequence of clicks with my browser, I have no problems.
      My library is composed by the following jar files:

       

      ant-1.5.4.jar
      apache-mime4j-0.6.jar
      aspectjrt-1.2.1.jar
      cactus-13-1.7.1.jar
      cactus-ant-13-1.7.1.jar
      cargo-0.5.jar
      commons-codec-1.4.jar
      commons-collections-3.2.1.jar
      commons-fileupload-1.2.1.jar
      commons-httpclient-2.0.2.jar
      commons-io-1.4.jar
      commons-lang-2.4.jar
      commons-logging-1.1.1.jar
      cssparser-0.9.5.jar
      htmlunit-2.8.jar
      htmlunit-core-js-2.8.jar
      httpclient-4.0.2.jar
      httpcore-4.0.1.jar
      httpmime-4.0.1.jar
      jboss-jsfunit-core-1.3.0.Final.jar
      jboss-jsfunit-richfaces-1.3.0.Final.jar
      jsf-api.jar
      jsf-facelets.jar
      jsf-ibm.jar
      jsf-impl.jar
      junit-3.8.1.jar
      nekohtml-1.9.14.jar
      richfaces-api-3.3.3.Final.jar
      richfaces-impl-3.3.3.Final.jar
      richfaces-ui-3.3.3.Final.jar
      sac-1.3.jar
      tomahawk-1.1.8.jar

       

      One important information is that my JSFUnit tests worked very well before, when I had the following set of libraries:

       

      ant-1.5.4.jar
      apache-mime4j-0.6.jar
      aspectjrt-1.2.1.jar
      cactus-13-1.7.1.jar
      cactus-ant-13-1.7.1.jar
      cargo-0.5.jar
      commons-codec-1.4.jar
      commons-collections-3.2.1.jar
      commons-fileupload-1.2.1.jar
      commons-httpclient-3.1.jar
      commons-io-1.4.jar
      commons-lang-2.4.jar
      commons-logging-1.1.1.jar
      cssparser-0.9.5.jar
      el-api-1.0.jar
      el-impl-1.0.jar
      groovy-all-1.5.5.jar
      htmlunit-2.7.jar
      htmlunit-core-js-2.7.jar
      httpclient-4.0.1.jar
      httpcore-4.0.1.jar
      httpmime-4.0.1.jar
      iText-2.1.7.jar
      jasperreports-3.7.2.jar
      jboss-jsfunit-core-1.2.0.Final.jar
      jsf-api.jar
      jsf-facelets.jar
      jsf-ibm.jar
      jsf-impl.jar
      junit-3.8.1.jar
      log4j-1.2.7.jar
      nekohtml-1.9.14.jar
      richfaces-api-3.1.4.GA.jar
      richfaces-impl-3.1.4.GA.jar
      richfaces-ui-3.1.4.GA.jar
      sac-1.3.jar
      serializer-2.7.1.jar
      tomahawk-1.1.8.jar

       

      If you think some other relevant information should be provided, please ask me for and I will post that as soon as possible.

       

      Thanks in advance for your kind support,
      Euler Xavier de Oliveira.

        • 1. Re: AJaX problems
          ssilvert

          These errors occur with my tests only. If I run the same sequence of clicks with my browser, I have no problems.
          My library is composed by the following jar files:

           

          ant-1.5.4.jar
          apache-mime4j-0.6.jar
          aspectjrt-1.2.1.jar
          cactus-13-1.7.1.jar
          cactus-ant-13-1.7.1.jar
          cargo-0.5.jar
          commons-codec-1.4.jar
          commons-collections-3.2.1.jar
          commons-fileupload-1.2.1.jar
          commons-httpclient-2.0.2.jar
          commons-io-1.4.jar
          commons-lang-2.4.jar
          commons-logging-1.1.1.jar
          cssparser-0.9.5.jar
          htmlunit-2.8.jar
          htmlunit-core-js-2.8.jar
          httpclient-4.0.2.jar
          httpcore-4.0.1.jar
          httpmime-4.0.1.jar
          jboss-jsfunit-core-1.3.0.Final.jar
          jboss-jsfunit-richfaces-1.3.0.Final.jar
          jsf-api.jar
          jsf-facelets.jar
          jsf-ibm.jar
          jsf-impl.jar
          junit-3.8.1.jar
          nekohtml-1.9.14.jar
          richfaces-api-3.3.3.Final.jar
          richfaces-impl-3.3.3.Final.jar
          richfaces-ui-3.3.3.Final.jar
          sac-1.3.jar
          tomahawk-1.1.8.jar

           

          I don't know for sure what would be wrong, but I do see in the list above that you are mixing httpclient-4.0.2 with httpcore-4.0.1.

           

          I also noticed that the HttComponents project has a 4.0.3 as the latest download.  You might try that for client/core/mime.

           

          If you have a simple example that fails under plain HttpUnit (with JSFUnit) then I can help you create something suitable to submit to the HtmlUnit team for a fix.

           

          In general, I know that a4j:commandButton will work just fine.  I have tests using that component that pass without error.

           

          Stan

          • 2. Re: AJaX problems
            exosys

             

            Stan,I discovered what is really happening. The "action" parameter of my a4j:commandButton refers to a method which returns a non-null String. The system is then configured to fire a "new" page, based on JSF navigation rules. However, that page is itslef!Programmers usually understand better with source code. So, here it is:The AJaX button (@ simulacaoUsuario.xhtml):<a4j:commandButton id="button_ID"image="/aparencia/botao_processar_on.gif" action="#{simulacaoUsuarioMB.simulaUsuario}"reRender="#{tratadorExcecoesMB.pathToMessage}, Menu, formularioSimulacao"/>The method executed when we click the button (@ simulacaoUsuarioMB.java):public String simulaUsuario() {             . . .     return "simulacaoUsuario";}The navigation rule (@ faces-config.xml):<navigation-case><from-outcome>simulacaoUsuario</from-outcome><to-view-id>simulacaoUsuario.xhtml</to-view-id></navigation-case>It means that I have an AJaX button firing a page transition to itself just to make an entire reload of the page (Bad programming practice, I suppose, since we can use AJaX)). We can correct this using one <h:commandButton> instead of a <a4j:commandButton>, or just making the "simulaUsuario" return null.Hopefully, this is going to be useful for other people experiencing this behaviour in this specific case. It was not being caught however when I used jboss-jsfunit-core-1.2.0.Final.jar and richfaces-*-3.1.4.GA.jar, for some reason I don´t know.Kind regards,Euler Xavier de Oliveira
            Stan,
            I discovered what is really happening. The "action" parameter of my a4j:commandButton refers to a method which returns a non-null String. The system is then configured to fire a "new" page, based on JSF navigation rules. However, that page is itslef!
            Programmers usually understand better with source code. So, here it is:
            The AJaX button (@ simulacaoUsuario.xhtml):
            <a4j:commandButton
            id="button_ID"
            image="/aparencia/botao_processar_on.gif"
            action="#{simulacaoUsuarioMB.simulaUsuario}"
            reRender="#{tratadorExcecoesMB.pathToMessage}, Menu, formularioSimulacao"/>
            The method executed when we click the button (@ simulacaoUsuarioMB.java):
            public String simulaUsuario() {
                         . . .
                 return "simulacaoUsuario";
            }
            The navigation rule (@ faces-config.xml):
            <navigation-case>
            <from-outcome>simulacaoUsuario</from-outcome>
            <to-view-id>simulacaoUsuario.xhtml</to-view-id>
            </navigation-case>
            It means that I have an AJaX button firing a page transition to itself just to make an entire reload of the page (Bad programming practice, I suppose, since we can use AJaX)). We can correct this using one <h:commandButton> instead of a <a4j:commandButton>, or just making the "simulaUsuario" return null.
            Hopefully, this is going to be useful for other people experiencing this behaviour due to this specific case. It was not happening however when I used jboss-jsfunit-core-1.2.0.Final.jar and richfaces-*-3.1.4.GA.jar, for some reason I don´t know.
            Kind regards,
            Euler Xavier de Oliveira

            Stan,

            I discovered what is really happening. The "action" parameter of my a4j:commandButton refers to a method which returns a non-null String. The system is then configured to fire a transition to load a "new" page, based on JSF navigation rules. However, that page is itslef! It means that the mistake was not in any library, but in my own code.

            Programmers usually understand better with source code. So, here it is:

             

            The AJaX button (@ simulacaoUsuario.xhtml):

             

            <a4j:commandButton
               id="button_ID"
               action="#{simulacaoUsuarioMB.simulaUsuario}"
               reRender="formularioSimulacao"/>
            

             

            The method executed when we click the button (@ simulacaoUsuarioMB.java):

             

            public String simulaUsuario() {
                        . . .
                return "simulacaoUsuario";
            }
            

             

            The navigation rule (@ faces-config.xml):

             

            <navigation-case>
               <from-outcome>simulacaoUsuario</from-outcome>
               <to-view-id>simulacaoUsuario.xhtml</to-view-id>
            </navigation-case>
            

             

            It means that I had an AJaX button firing a page transition to itself just to make an entire page reload. We can correct this (bad programming practice, I suppose) using one <h:commandButton> instead of a <a4j:commandButton>, or just making the "simulaUsuario()" method return null.Hopefully, this is going to be useful for other people experiencing this behaviour due to some mistake similar to mine. It was not being caught however when I used jboss-jsfunit-core-1.2.0.Final.jar and richfaces-*-3.1.4.GA.jar, for some reason I don´t know.

             

            Kind regards,

             

            Euler Xavier de Oliveira