0 Replies Latest reply on Jul 7, 2009 7:42 PM by Arbi Sookazian

    rich:progressBar and scoping-conversation mgmt

    Arbi Sookazian Master

      I have a rich:progressBar (actually two of them) and one a4j:commandButton to start the polling of them.  One calls a web service and the other inserts into local DB.


      I am having problems understanding/implementing conversation management for these two POJOs (if even required).  I currently have them scoped to SESSION.  But they ideally should not be session-scoped, rather event-scoped if possible (like a stateless service).


      The problem is that there are instance variables that require the maintaining of state for subsequent method calls to use them (i.e. the getCurrentValue() method is called multiple times).


      The http://livedemo.exadel.com/richfaces-demo/richfaces/progressBar.jsf bean source does not use the @Name Seam annotation for obvious reasons (to keep it framework agnostic).


      So what is the recommendation here?  thx.


      .xhtml:


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich" 
              xmlns:a4j="http://richfaces.org/a4j"
              template="/templates/normal.xhtml">
              
              <ui:define name="body">
                              
                       <h:form>
                              <rich:panel id="progressPanel">
                                      <h3>Updating ERS</h3>
                                  <rich:progressBar value="#{progressBarLocalDB.currentValue}"
                                                                interval="1000" 
                                                                label="#{progressBarLocalDB.label}"
                                                                enabled="#{progressBarLocalDB.enabled}" 
                                                                completeClass="color: yellow;"
                                                                finishClass="color: red;"
                                                                minValue="-1"
                                                                maxValue="100"
                                                                reRenderAfterComplete="progressPanel">
                                  
                                      <f:facet name="complete">
                                          <br />
                                          <h:outputText value="Process Done" />
                                      </f:facet>
                                                                
                                  </rich:progressBar>
                                                                                  
                                  <rich:spacer height="20"/>
                                                          
                                      <h3>Adding ICOMS Note</h3>
                                  <rich:progressBar value="#{progressBarWebService.currentValue}"
                                                                interval="1000" 
                                                                label="#{progressBarWebService.label}"
                                                                enabled="#{progressBarWebService.enabled}" 
                                                                minValue="-1"
                                                                maxValue="100"
                                                                reRenderAfterComplete="progressPanel">
                                      <f:facet name="complete">
                                          <br />
                                          <h:outputText value="Process Done" />
                                      </f:facet>
                                      
                                </rich:progressBar>
                                  
                              </rich:panel>
                              <rich:spacer height="40"/>
                              <a4j:commandButton action="#{progressBarWebService.startProcess}"
                                                                         value="Submit" 
                                                                         reRender="progressPanel"                                                                
                                                                         style="margin: 9px 0px 5px;" />
                          </h:form>
                      
              </ui:define>
      
      </ui:composition>



      POJO1:


      @Name("progressBarWebService")
      @Scope(ScopeType.SESSION)
      public class TestProgressBarWebServiceAction {
                      
                      @Logger Log log;
                      @In WebServiceCallActionLocal webServiceCaller;
                      @In FacesMessages facesMessages; 
                      @In TestProgressBarLocalDBAction progressBarLocalDB;
              
                      private Boolean buttonRendered = true;
                  private Boolean enabled = false;
                  private Boolean readyToCallWebService = false;
                  private Boolean webServiceComplete = false;
                  private Long startTime;
                  private String startLabel = "Processing...";
                  //private String finishLabel = "Complete.";
                                  
                  @Begin(join=true)
                  public String startProcess() {
                              
                      setEnabled(true);
                      setButtonRendered(false);
                      setStartTime(new Date().getTime());
                      
                      progressBarLocalDB.startProcess();
                      
                      return null;
                  }
      
                  public Long getCurrentValue(){
                      if (!enabled){
                              return Long.valueOf(-1);
                      }
                      else if(enabled && !readyToCallWebService){
                              readyToCallWebService = true;
                              return Long.valueOf(100);
                      }
                      else if(enabled && readyToCallWebService && !webServiceComplete){
                              //callWebService();                             
                              webServiceComplete = true;
                              return Long.valueOf(101);                       
                      }              
                      else {
                              //reset variables
                              //resetVariables();
                              enabled = false;
                                  readyToCallWebService = false;
                                  webServiceComplete = false;
                              return Long.valueOf(101);
                      }
                                              
                  }
                  
                  private boolean callWebService(){
                      try{
                              return webServiceCaller.addCustomerComments();
                      }
                      catch(CoxWseWebServiceException wse){
                              log.error("TestProgressBarWebServiceAction.callWebService(): caught CoxWseWebServiceException: ", wse);
                              facesMessages.add("Error occurred during add customer comment web service call.");
                              return false;
                      }
                      catch(Exception e){
                              log.error("TestProgressBarWebServiceAction.callWebService(): caught Exception: ", e);
                              facesMessages.add("Error occurred during add customer comment web service call.");
                              return false;
                      }
                  }
                  
                  public boolean isEnabled() {
                      return enabled;
                  }
      
                  public void setEnabled(boolean enabled) {
                      this.enabled = enabled;
                  }
      
                  public Long getStartTime() {
                      return startTime;
                  }
      
                  public void setStartTime(Long startTime) {
                      this.startTime = startTime;
                  }
      
                  public boolean isButtonRendered() {
                      return buttonRendered;
                  }
      
                  public void setButtonRendered(boolean buttonRendered) {
                      this.buttonRendered = buttonRendered;
                  }
      
                      public String getLabel() {
                              return startLabel;                      
                      }
      
                      
              
      }
      



      POJO2:


      @Name("progressBarLocalDB")
      @AutoCreate
      @Scope(ScopeType.SESSION)
      public class TestProgressBarLocalDBAction {
                      
                      @Logger Log log;
                              
                      private Boolean buttonRendered = true;
                  private Boolean enabled = false;
                  private Long startTime;
                  private String startLabel = "Processing...";
                  private String finishLabel = "Complete.";
                  private Integer maxExecs = 0;
                          
                  @Begin(join=true)
                  public String startProcess() {
                      
                      setEnabled(true);
                      setButtonRendered(false);
                      setStartTime(new Date().getTime());
                      return null;
                  }
                  
                  public Long getCurrentValue(){
                      if (!enabled){
                              return Long.valueOf(-1);
                          }
                      if (enabled && maxExecs < 3){
                              maxExecs++;
                              return Long.valueOf(100);
                      }       
                      if (enabled && maxExecs.intValue() == 3){
                              maxExecs = 0;
                              enabled = false;                        
                                  return Long.valueOf(101);
                      }
                      
                      return Long.valueOf(101);
                  }
                  
                  public boolean isEnabled() {
                      return enabled;
                  }
      
                  public void setEnabled(boolean enabled) {
                      this.enabled = enabled;
                  }
      
                  public Long getStartTime() {
                      return startTime;
                  }
      
                  public void setStartTime(Long startTime) {
                      this.startTime = startTime;
                  }
      
                  public boolean isButtonRendered() {
                      return buttonRendered;
                  }
      
                  public void setButtonRendered(boolean buttonRendered) {
                      this.buttonRendered = buttonRendered;
                  }
      
                      public String getLabel() {
                              //if(!webServiceCalled)
                                      return startLabel;
                              //else
                                      //return finishLabel;
                      }
                      
                      @Destroy
                      public void destroy(){
                              log.info("in destroy() for TestProgressBarLocalDBBean");
                      }
      
                      
              
      }