9 Replies Latest reply on Jan 31, 2011 5:44 AM by topfan

    How to show progress value on rich:modalPanel

    topfan Newbie

      I've got this code:

       

      ..................................................................................................................

       

      <a4j:status

          id="waitStatus"

          forceId="true"

          onstart="javascript:Richfaces.showModalPanel('waitModalPanel');"

          onstop="javascript:Richfaces.hideModalPanel('waitModalPanel');"/>

      <rich:modalPanel

          id="waitModalPanel"

          autosized="true"

          width="200"

          height="120"

          moveable="false"

          resizeable="false">

          <f:facet name="header">

              <h:outputText value="Processing"/>

          </f:facet>

          <h:outputText value="Please wait..."/>

      </rich:modalPanel>

       

       

      <a4j:commandButton

          action="#{myBean.doBtnActn}"

          value="Start"

          status="waitStatus"/>

       

       

      ......................................................................................................................

       

      When i click on the Start button, a java process start.

      It's a very simple count code (10 seconds):

       

       

      .........

       

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

       

          Thread.sleep(1000);

       

      }

       

      .........

       

      What can i do to show the progress of "i" value on modalpanel????

       

      Thanks

       

       

      topfan

        • 3. How to show progress value on rich:modalPanel
          topfan Newbie

          Another problem, i'm afraid.

          If i set to "true" the enabled attribute of a4j:poll, it work but the poll never stop.

          But if i set the enabled attribute to bean property, the poll start only at the end of request. Belowe my code:

           

          xhtml page:

           

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml"

              xmlns:ui="http://java.sun.com/jsf/facelets"

              xmlns:h="http://java.sun.com/jsf/html"

              xmlns:f="http://java.sun.com/jsf/core"

              xmlns:rich="http://richfaces.org/rich"

              xmlns:a4j="http://richfaces.org/a4j">

          <ui:composition>

              <f:view>

                  <h:form>

                      <a4j:poll id="poll" interval="500" enabled="#{pc_Prova.enabled}"

                          reRender="clock" timeout="20000" />

                  </h:form>

                  <h:form>

                      <h:panelGrid columns="2">

                          <h:panelGrid columns="2">

                              <a4j:commandButton value="Start Clock"

                                  action="#{pc_Prova.startClock}" reRender="poll"

                                  status="waitStatus" ajaxSingle="true">

                                  <a4j:actionparam name="disabled" value="true"

                                      assignTo="#{pc_Prova.enabled}"></a4j:actionparam>

                              </a4j:commandButton>

                          </h:panelGrid>

           

                      </h:panelGrid>

                      <a4j:status id="waitStatus" forceId="true" layout="block"

                          onstart="javascript:Richfaces.showModalPanel('waitModalPanel');"

                          onstop="javascript:Richfaces.hideModalPanel('waitModalPanel');"  />

           

                      <rich:modalPanel id="waitModalPanel" autosized="true" width="300"

                          height="70" moveable="true" resizeable="false"

                          style="text-align: center;">

                          <f:facet name="header">

                              <h:outputText id="txtHeaderWait" value="Attendere" />

                          </f:facet>

                          <h:outputText id="label" value="Secondi trascorsi: "></h:outputText>

                          <h:outputText id="clock" value="#{pc_Prova.counter}" />

                          <a4j:commandButton value="Stop Clock" action="#{pc_Prova.stopClock}"

                              reRender="poll">

                              <a4j:actionparam name="enabled" value="false"

                                  assignTo="#{pc_Prova.enabled}"></a4j:actionparam>

                          </a4j:commandButton>

                      </rich:modalPanel>

                  </h:form>

              </f:view>

          </ui:composition>

          </html>

           

          Java code:

          =======

           

          package pagecode;

           

          public class Prova extends PageCodeBase {

           

              protected String counter;

           

              private boolean enabled;

           

              public boolean isEnabled() {

                  return enabled;

              }

           

              public String getCounter() {

                  return counter;

              }

           

              public void setCounter(String counter) {

                  this.counter = counter;

              }

           

           

              public String stopClock() {

                  enabled = false;

                  counter = null;

                  return null;

              }

           

              public String startClock() throws InterruptedException {

                  enabled = true;

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

                      counter = String.valueOf(i);

                      Thread.sleep(1000);

                      if (!enabled) {

                          counter = null;

                          return null;

                      }

                  }

                  counter = null;

                  return null;

              }

           

          }

           

           

          Any suggestions?

           

          Thanks in advance

          • 4. How to show progress value on rich:modalPanel
            Ilya Sorokoumov Master

            Take a look at this link:

            http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_poll.html

            It contains an example how to disable a4j:poll

            • 5. How to show progress value on rich:modalPanel
              Ilya Sorokoumov Master

              Ooops. I see that you are already aware of this link. =)

              • 6. How to show progress value on rich:modalPanel
                Ilya Sorokoumov Master
                But if i set the enabled attribute to bean property, the poll start only at the end of request. Belowe my code:

                When do want it to start pulling?

                • 7. How to show progress value on rich:modalPanel
                  topfan Newbie

                  When i click on "Start Clock" ajax request start and start my java process ( counter ) that show modal panel.

                  If the enabled property of poll is set to "true" it work, the progress counter is shown on modal panel, but generates too much server request.

                  But if the enabled property is set to "#{pc_Prova.enabled}", it does not work because the polling is not active.

                  My question is:

                   

                  Is it possible to start polling when start java process, show the progress counter on the modal panel, stop polling and hide modal panel at the end of process?

                   

                  Thanks for your answer.

                  • 8. How to show progress value on rich:modalPanel
                    Ilya Sorokoumov Master

                    Why can't you just set "#{pc_Prova.enabled}" to true and reRender a4j:poll when you need it to be started and set "#{pc_Prova.enabled}" to false and reRender a4j:poll when you need it to be stopped?

                     

                    P.S. Take a look at this link(It's about JS api):

                    http://community.jboss.org/thread/148465?tstart=1

                    • 9. How to show progress value on rich:modalPanel
                      topfan Newbie

                      I'm usin RF 3.1.6 so A4J.AJAX.StartPoll is not present.

                       

                      Unfortunatelly A4J.AJAX.StopPoll, in my code, does not work :-(

                       

                      Code:

                       

                      ...........

                       

                              <a4j:region id="region">

                                  <h:form id="pollForm">

                                      <a4j:poll id="poll" interval="500" enabled="true" reRender="poll,clock"

                                          timeout="20000" />

                                  </h:form>

                              </a4j:region>

                       

                       

                      .........................................................................................................................

                      .........................................................................................................................

                       

                                      <a4j:commandButton value="Stop Clock" action="#{pc_Prova.stopClock}"

                                          reRender="poll,clock" onclick="A4J.AJAX.StopPoll('pollForm:poll');">

                                          <a4j:actionparam name="enabled" value="false"

                                              assignTo="#{pc_Prova.enabled}"></a4j:actionparam>

                                     </a4j:commandButton>

                       

                       

                      When i click on "Stop Clock" the polling do not stop.

                       

                      Something wrong?

                       

                      Suggestion?

                       

                      Thanks.

                       

                      topfan