14 Replies Latest reply on Oct 19, 2008 1:12 PM by nimo22

    <rich:progressBar actualValue does not work within for-loop

    nimo22

      Look at my progressBar:

      <rich:progressBar value="#{myBean.actualValue}"
       interval="1000" label="#{myBean.actualValue} %"
       minValue="-1" maxValue="1000">
      </rich:progressBar>


      The actualValue is caluculated within a for-loop (in my managedBean):

      
      public void doJob() {
      
      for (int i=1; i<= 10000; i++)
      {
      // current value of ProgressBar
      this.setActualValue(i);
      }
      
      }


      Unfortunately, this does NOT work!

      When I set the actualValue NOT in a scope of the for-loop, then it works!

      For example:

      public void doJob() {

      // current value is calculated out of scope of my for-loop
      this.setActualValue(this.setActualValue+1);

      for (int i=1; i<= 10000; i++)
      {
      ...
      }

      }

        • 1. Re: <rich:progressBar actualValue does not work within for-l

          I suppose that problem in synchronization of methods calls. Seems that your bean does not return progressBar's actual value before loop will be finished.

          You should put job method in an another thread and set actual value by calling setActualValue.

          • 2. Re: <rich:progressBar actualValue does not work within for-l
            panky_p

            Hi, I am also having the same scenario.
            Now as andrei_exadel suggested I give it try but no success.
            What I am doing wrong??

            <a4j:outputPanel id="progressPanel">
             <a4j:commandButton value="Start" action="#{myBean.startCount()}" />
             <rich:progressBar value="#{myBean.counts}" enabled="true" label="#{myBean.counts} %" mode="ajax" minValue="-1" maxValue="100"/>
            </a4j:outputPanel>

            and in managed bean
            public class MyBean{
            ...
            public String startCount(){
            ....
             MyThread newTh= MyThread();
             newTh.start();
            }
            
            public int getCount() {
             return emailSendingProgress;
             }
            
            public void setCount(int count) {
             this.count = count;
            }
            
            
            public class MyThread extends Thread{
             public void run(){
             for(int i=1; i<= 100; i++ ){
             ....
             counts = i+1;
             .....
             }
             }
            }
            
            }


            Is there anything wrong???
            Please help!!!

            • 3. Re: <rich:progressBar actualValue does not work within for-l
              panky_p

              Hi, I am also having the same scenario.
              Now as andrei_exadel suggested I give it try but no success.
              What I am doing wrong??

              <a4j:outputPanel id="progressPanel">
               <a4j:commandButton value="Start" action="#{myBean.startCount()}" />
               <rich:progressBar value="#{myBean.counts}" enabled="true" label="#{myBean.counts} %" mode="ajax" minValue="-1" maxValue="100"/>
              </a4j:outputPanel>

              and in managed bean
              public class MyBean{
              ...
              public String startCount(){
              ....
               MyThread newTh= MyThread();
               newTh.start();
              }
              
              public int getCount() {
               return count;
               }
              
              public void setCount(int count) {
               this.count = count;
              }
              
              
              public class MyThread extends Thread{
               public void run(){
               for(int i=1; i<= 100; i++ ){
               ....
               counts = i+1;
               .....
               }
               }
              }
              
              }


              Is there anything wrong???
              Please help!!!

              • 4. Re: <rich:progressBar actualValue does not work within for-l
                panky_p

                sorry for re posting ...
                Is there any way to remove duplicate messages???

                • 5. Re: <rich:progressBar actualValue does not work within for-l
                  nimo22

                  Hello,

                  I have done it without success:

                  public bean() {
                  
                  public void increment(){
                  
                  this.setActualValue(this.getActualValue+1);
                  
                  }
                  
                  public void doJob() {
                  
                  for (int i=1; i<= 10000; i++)
                  {
                  // call method
                  this.increment();
                  }
                  
                  }
                  
                  }


                  andrei_exadel said:
                  Seems that your bean does not return progressBar's actual value before loop will be finished.


                  In my console, I have logged the actualValue - the incremention works, but the progressBar cannot retrieve that value. I have tried to do it with the rich:poll-component and the same failure occurs. I also tried to set the interval higher or lower, without success.

                  I guess, a loop increments the actual value too fast, so the progressBar cannot update it properly.

                  So for what reason do I need the rich:progressBar, when it does NOT work within a loop ????


                  • 6. Re: <rich:progressBar actualValue does not work within for-l
                    nimo22

                    I have found the reason:

                    Look at this:
                    http://www.jboss.com/index.html?module=bb&op=viewtopic&t=140796

                    I have the same failure:

                    ConversationEndedTimedOutOrWasProcessingAnotherRequest


                    I found in the RichFaces Reference page 44 this:
                    "Queue and Traffic Flood Protection"


                    So I assume that I have to declare anything in the eventsQueue...HOW?

                    The rich:progressBar has the following property:
                    eventsQueue:
                    Name of requests queue to avoid ...


                    It is not very comfortable...what (how) should I declare, that this process comes after that?

                    I cannot give the property such as:
                    <rich:progressBar eventsQueue="doThisFirst, doThisAfter"




                    • 7. Re: <rich:progressBar actualValue does not work within for-l
                      panky_p

                      In for loop if we are not able to make use of rich:progressBar I think experts must have solution on this.
                      BTW making use of eventsQueue is not good idea as nimo22 said

                      It is not very comfortable...what (how) should I declare, that this process comes after that?

                      By making use of threads also not much comfortable, as what i give in my last post it is not successful implementation.

                      Is there anyone in the forum who can explain, how to handle this situation???


                      • 8. Re: <rich:progressBar actualValue does not work within for-l

                        Guys,

                        Please start from your environment definition.
                        As I understood you use SEAM + RF.
                        In this case post your versions & conversation settings.

                        • 9. Re: <rich:progressBar actualValue does not work within for-l

                          Anyway this code works in RF 3.2.2.GA + JSF 1.2_09 + Tomcat.

                          • 10. Re: <rich:progressBar actualValue does not work within for-l
                            panky_p

                            As I am using RF 3.2.1GA Seam 2.0 and JSF 1.2 with Jboss -4.2.0.GA.

                            I am using as stateful MyBean with the session scope.

                            • 11. Re: <rich:progressBar actualValue does not work within for-l
                              nimo22

                              I am using
                              - RichFaces 3.2.2.GA
                              - Seam 2.1
                              - JBOSS 4.2

                              All actual versions.

                              Thank you for helping

                              • 12. Re: <rich:progressBar actualValue does not work within for-l
                                panky_p

                                Well but if problem seems to in call of methods which holds control.
                                What I want is after each iteration in for loop should increment the counter and the updated value should reflect immediately on browser, but it is not doing so.
                                Any suggestions???

                                • 13. Re: <rich:progressBar actualValue does not work within for-l

                                  My code:

                                  @Local
                                  public interface ITest {
                                  
                                   public void remove();
                                  
                                   public Integer getValue();
                                  
                                   public void setValue(Integer i);
                                  
                                  }



                                  @Stateful
                                  @Name("testBean")
                                  @Scope(ScopeType.SESSION)
                                  @AutoCreate
                                  @SessionExpired
                                  public class Test implements ITest {
                                  
                                   Integer v;
                                  
                                   public Test() {
                                   MyThread t = new MyThread();
                                   t.start();
                                   }
                                  
                                   public class MyThread extends Thread {
                                   @Override
                                   public void run() {
                                   for (int i = 0; i < 100; i++) {
                                   v = i;
                                   try {
                                   sleep(1000);
                                   }catch (Exception e) {
                                   // TODO: handle exception
                                   }
                                   }
                                   }
                                   }
                                  
                                   /* (non-Javadoc)
                                   * @see org.richfaces.regressionarea.seam.interfaces.ITest#getValue()
                                   */
                                   public Integer getValue() {
                                   // TODO Auto-generated method stub
                                   return v;
                                   }
                                  
                                   /* (non-Javadoc)
                                   * @see org.richfaces.regressionarea.seam.interfaces.ITest#remode()
                                   */
                                   @Remove
                                   public void remove() {
                                   // TODO Auto-generated method stub
                                  
                                   }
                                  
                                   /* (non-Javadoc)
                                   * @see org.richfaces.regressionarea.seam.interfaces.ITest#setValue(java.lang.Integer)
                                   */
                                   public void setValue(Integer i) {
                                   v = i;
                                  
                                   }
                                  
                                  }


                                  Page:



                                  <body id="pgHome">
                                  ...
                                  <f:view>
                                   <h:form id="_form">
                                   Successfull
                                   <rich:progressBar value="#{testBean.value}" enabled="true">
                                   <h:outputText value="{value}%"></h:outputText>
                                   </rich:progressBar>
                                   </h:form>
                                  </f:view>
                                  </body>
                                  ....
                                  


                                  Environment: RF 3.2.2.GA, Seam 2.0.1, JBOSS-4.2.1, JSF 1.2_09
                                  Projects packages as EAR with EJB support.


                                  This code works for me. ProgressBar updates every second and shows value from 0 till 99.

                                  • 14. Re: <rich:progressBar actualValue does not work within for-l
                                    nimo22

                                    Hello Andrei,

                                    yes, your code works (for me, too:-)

                                    The only difference I had, was that I outjected the progressbar s current value:

                                    @Out
                                    Integer v;

                                    you have assigned explicitly getter/setter.

                                    Strange..well, now it works.

                                    thanks.