1 Reply Latest reply on Apr 26, 2012 6:04 PM by Roger Lee

    Seam & Rich Faces Progress bar

    Roger Lee Apprentice

      I am having trouble getting the RichFaces (RF) Progress bar to display a % progress when it is kicked off from an a4j:commandButton whose action calls a method in a SLSB 1, which in turn calls another method in another SFSB 2.

       

      <rich:progressBar value="#{progressBarBean.percentageComplete}" interval="1000" label="#{progressBarBean.percentageComplete} %" minvalue="-1" maxValue="100" enabled="#{progressBarBean.enabled}" reRenderAfterComplete="progressPanel" >

      </rich:progressBar>

       

      <a4j:commandButton action="#{documentBean.sendToDevice}" reRender="progressPanel" value="Send To Device" rendered="#{progressBarBean.buttonRendered}" id="commandButton" >

      </a4j:commandButton>

       

      EJB 1.

       

      @Asynchronous

      @Begin(join = true)

      public final String sendToDevice() {

       

       

           progressBarBean.startProcess(); //POJO as per demo code

       

               convertPDFLocal.extractPageContentImages( ..... ) // Call to method in EJB 2

          

      A method in the 2nd SFSB calculates the % completed and updates the POJO’s method (setPercentageComplete) which is polled every second by the RF Progress Bar to get this percentage (from the POJO’s getPercentageComplete)

       

      EJB 2.

       

      public void extractPageContentImages(final String fileName) throws IOException {

       

           double percentage = (dCount / dNumberPages) * ONE_HUNDRED;

       

           progressBarBean.setPercentageComplete((new Double(percentage)).longValue());

       

      }

       

      What happens in that the two methods in the 2 x SFSB are executed (one after the other). I can see the % being calculated and set in the POJO in the log. It's only once (the two SFSB) have finished that the RF Progress Bar appears on the page and immediately displays 100%!

       

      Basically followed the server example on the RF demo page using SFSB instead of just a POJO.

       

      Are there any issues using an EJB as the "backing bean"?

        • 1. Re: Seam & Rich Faces Progress bar
          Roger Lee Apprentice

          I fixed this by;

           

          Annotating the "long process" with the Seam @Asynchronous (org.jboss.seam.annotations.async.Asynchronous) and all the methods that the method calls and removing the "@Begin(join = true)".

           

          EJB 1.

           

          @Asynchronous

          public final void sendToDevice() {

           

               ......

           

               convertPDFLocal.extractPageContentImages( ..... ) // Call to method in EJB 2

           

          }

           

          EJB 2

           

          @Asynchronous

          public void extractPageContentImages(final String fileName) throws IOException {

           

               double percentage = (dCount / dNumberPages) * ONE_HUNDRED;

           

               progressBarBean.setPercentageComplete((new Double(percentage)).longValue());

           

          }

           

          The ProgressBean is injected into each EJB so;

           

          @In(create = true)

          private ProgressBarBean progressBarBean;

           

          The ProgressBarBean;

           

          @Name("progressBarBean")

          @Scope(ScopeType.SESSION)

          public class ProgressBarBean implements Serializable {

           

                    /**

                     *

                     */

                    private static final long serialVersionUID = 1L;

           

           

                    @Logger

                    private Log log;

           

           

                    private boolean buttonRendered = true;

                    private boolean enabled = true;

                    private Long percentageComplete = new Long(-1);

           

           

                    public ProgressBarBean() {

                    }

           

                    public Long getPercentageComplete() {

               ......

                }

           

               public void setPercentageComplete(Long percentageComplete) {

                                   this.percentageComplete = percentageComplete;

                    }

           

          }