6 Replies Latest reply on Mar 1, 2010 8:44 AM by nimo stephan

    a4j:poll polls but not update the view

    nimo stephan Master

      I want to poll a area:

       

      {code}

      <a4j:outputPanel id="my_panel">

           <h:form id="form_poll">

              <a4j:poll id="poll" interval="500" enabled="#{myBean.start}" reRender="poll_status" limitToList="true" ajaxSingle="true"/>

          </h:form>

       

      <a4j:outputPanel id="poll_status">


        <s:div id="progress_status_start" rendered="#{myBean.start}">


          <h:outputText value="#{myBean.actualPosition} of #{myBean.size} done" />


        </s:div>


      </a4j:outputPanel>

       

       

      <h:form id="formTrigger">

       

      <a4j:commandButton action="#{myBean.initPoll}" value="init Poll" reRender="form_poll, poll_status" limitToList="true" ignoreDupResponses="true">

        <a4j:support event="oncomplete" action="#{myBean.changeActualPosition(1500)}" reRender="form_poll" limitToList="true" ignoreDupResponses="true"/>

      </a4j:commandButton>

       

      </h:form>

       

      </a4j:outputPanel>

      {code}

       

      and my code:

       

      {code}

      public void initPoll()
      {

      setActualPosition(0);

      setSize(50);

      setStart(true);

      }

       

      @Asynchronous

      public void changeActualPosition(long ms) throws Exception
        {

        for(int i=1; i<50; i++)

      {

      setActualPosition(i);

      Thread.sleep(ms);

      log.info("actual Pos: #0", i);

      }


      }

      {code}

       

       

      You see, initPoll enables the a4j:poll by rerendering the area (this works).

       

      After triggering the action "myBean.changeActualPosition(1500)", it changes by the value  'myBean.actualPosition'.

      But the values in the view does not update after a poll-request. (however, the polling works as my logger shows the phases of my phaselistener)

       

      I want that the poll-request updates the value of myBean.actualPosition not only in the code but also in my view.

       

      What is wrong?

        • 1. Re: a4j:poll polls but not update the view
          nimo stephan Master

          I have figured out the problem: When using this code:

           

          public void changeActualPosition(long ms) throws Exception  {
            for(int i=1; i<50; i++)
          {
          setActualPosition(i);
          Thread.sleep(ms);
          log.info("actual Pos: #0", i);
          }

          }

          My logger tell me that failure (so this is the reason why my values are not updated by the poll):

           

           

          11:58:45,219 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1dc6a3b
          11:58:45,219 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_4] TwoPhaseCoordinator.afterCompletion - returned failure for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1c27073
          11:58:45,219 ERROR [CachedConnectionValve] Application error: Faces Servlet did not complete its transaction
          11:58:45,781 INFO  [STDOUT] BeforePhase: RESTORE_VIEW 1
          11:58:45,797 INFO  [STDOUT] AfterPhase: RESTORE_VIEW 1
          11:58:46,297 WARN  [SeamPhaseListener] uncaught exception, passing to exception handler
          org.jboss.seam.ConcurrentRequestTimeoutException: Concurrent call to conversation
              at org.jboss.seam.core.Manager.restoreAndLockConversation(Manager.java:641)
              at org.jboss.seam.core.Manager.restoreConversation(Manager.java:603)
              at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:390)
              at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:228)
              at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)

           

           

          So you see, the seam error "Concurrent call to conversation" is thrown!

           

          How can I avoid it?
          (It makes no difference, if I use @Asynchronous - the same error occurs "Concurrent call to conversation"!).
          • 2. Re: a4j:poll polls but not update the view
            Ilya Shaikovsky Master

            At first - do not use support in a4j:command* and the other components on events which causes ajax requests. This causes two requests to be sent. In your case - one from button and the second from support. Button itself is enough to rise ajax call.

             

            And at second if you have poll and the other components and need the reuqest not to interfere with each other look to a4j:queue component documentation.

            • 3. Re: a4j:poll polls but not update the view
              nimo stephan Master

              I must admit, I have not ever used the <a4j:queue>.

               

              But I guess, my problem lays in the fact,

              that a action of a bean (which also serves the value for my polled data), is not invoked in another thread.

               

              I have no clue.

               

              I am using this code:

               

               

              {code}

              <a4j:outputPanel id="my_panel">


              <!--My Poll-Region -->

               

              <a4j:region>

                <h:form id="form_poll">


                  <a4j:poll id="poll" interval="1000" enabled="true" reRender="polled_region"


                     limitToList="true" ajaxSingle="true" ignoreDubResponse="polled_region"></a4j:poll>


                </h:form>


              </a4j:region>


              <!-- MY REGION WHICH IS POLLED -->


              <a4j:outputPanel id="polled_region">


                  <h:outputText value="#{myBean.actualDate}></h:outputText>


              </a4j:outputPanel>


              <!-- MY FORM WHICH INVOKES A ACTION


              - Triggering the Action disturbes the polled region to update as long as the action is running!

              - After action ends, the polled region starts updating again!

              - But I need the polled update also while action is running! -->


              <h:form id="formTrigger">


                  <a4j:commandButton action="#{myBean.updateRows}" value="update Data">

                  </a4j:commandButton>    


              </h:form>


              </a4j:outputPanel>


              {code}

               

              my Bean -Action for getting the actual date:

               

              {code}

              @Name("myBean")
              @Scope(CONVERSATION)
              public class MyBean{

               

              // this method can end after a long time (for example 20 seconds)

              // and while this method is active, the a4j:poll is disturbed

              public void updateRows() throws Exception{

               

              // do database operations...

               

              }

              ...

               

              // this returns the polled value

              public Date getDate()

              {

              return new Date();

              }

              ..

              {code}

               

              The poll works, the date gets updated each second.

               

              But when I trigger the action "updateRows",

              then the polled region disturbs as long as the action takes and after action has completed, the polled region is continuing to update its date.

               

              The polled region is disturbed by this exception (which is thrown via updateRows):

               

              {code}

              16:31:31,548 WARN  [SeamPhaseListener] uncaught exception, passing to exception handler


              org.jboss.seam.ConcurrentRequestTimeoutException: Concurrent call to conversation


                  at org.jboss.seam.core.Manager.restoreAndLockConversation(Manager.java:641)


                  at org.jboss.seam.core.Manager.restoreConversation(Manager.java:603)


                  at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:390)


                  at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:228)

               

              {code}

               

              This exception comes after each second (poll-interval="1000") while "updateRows"-Method is running.

              After "updateRows"-Method ends, the polled region works correctly again without any exception.

               

              How can a4j:poll updates its region while action "updateRows" is running?

               

              Should I put the Method "updateRows" in another thread?

               

              I really have no clue.

              • 4. Re: a4j:poll polls but not update the view
                nimo stephan Master

                Okay I found the problem.

                 

                According to RF-documentation:

                 

                {quote}

                Try to avoid updating the same server data that might be updated by the
                Ajax requests produced by the user activities. If you need this, be sure your code

                allows to access the data from parallel thread without conflicts;

                {quote}

                 

                This is my problem, I have to get the current Values from within another thread while the updateRows-Method excecutes in the actual Thread.

                 

                So I tried it this way:

                 

                {code}

                @Name("myBean")


                @Scope(CONVERSATION)


                public class MyBean{

                 

                public void updateRows() throws Exception
                {

                 

                MyThread polledThread = new MyThread();


                polledThread.start();

                 

                //long running process..

                ...

                 

                }

                 

                public class MyThread extends Thread


                {
                @Override


                public void run()


                {
                for (int i = 0; i < 100; i++)


                {
                   v = i;

                 

                   date = new Date();


                   try  { sleep(1000); }


                   catch (Exception e) {}
                }


                }


                }

                 

                 

                private Integer v;


                public Integer getValue() { return v; }


                public void setValue(Integer i) { v = i;}

                 

                private Date date;


                public void setDate(Date date) {this.date = date;}


                public Date getDate() {return date;}

                {code}

                 

                 

                But I get the same failure as without using a additional thread:

                org.jboss.seam.ConcurrentRequestTimeoutException: Concurrent call to conversation..

                • 6. Re: a4j:poll polls but not update the view
                  nimo stephan Master

                  Hello Ilya,

                   

                  thanks for the information.

                   

                  I have used the a4j:queue, but there is a dilemma in using the a4j:queue with a4j:push and a4j:poll. I figured out the problem in a new thread:

                   

                  http://community.jboss.org/thread/148777