1 Reply Latest reply on Mar 29, 2012 10:12 AM by serkan

    Ajax call to the result of long-running process

    llamer

      Hi, All.

      I have a problem with getting result of long-running process, it returns null when the process is in progress.

      I've tried to make like discribes here http://docs.jboss.com/seam/2.0.1.GA/reference/en/html/conversations.html#d0e5208

       

      I saw many topics in this forum, but didn't find any working example. Could you help me?...

      Here the example i try to make it work:

       

      I'm using Seam 2.2.0.GA.

       

      someAction.page.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
      
          <begin-conversation join="true"/>
      </page>
      

       

      someAction.xhtml:

       

      <a4j:region>
           <h:form>
                <a4j:poll id="poll"  enabled="#{someAction.enablePolling}" reRender="consoleOutput,poll" />
           </h:form>
      </a4j:region>
      
      <h:form>
           <a4j:jsFunction name="startBuild" action="#{someAction.startBuild}" />
           <a4j:commandButton value="Start Build"  action="#{someAction.startPolling}" oncomplete="startBuild()" reRender="poll" />
           <hr/>
           <h:outputText id="consoleOutput" value="#{someAction.consoleOutput}" escape="false"/>
      </h:form>
      

       

      SomeAction.java

       

      @Name("someAction")
      @Scope(ScopeType.CONVERSATION)
      public class SomeAction {     
           private static final int SLEEP_SEC = 1000;
           private static final int ENTIRIES = 10;
      
           private boolean enablePolling;
           private StringBuffer buildOutputSb = new StringBuffer();
           private String consoleOutput;    
      
           public boolean isEnablePolling() {
              return enablePolling;
           } 
      
           public void setEnablePolling(boolean enablePolling) {
              this.enablePolling = enablePolling;
           } 
      
           public void startPolling(){
              this.enablePolling = true;
           }
      
           public String getConsoleOutput() {
              return this.buildOutputSb.toString();
           }
      
           @Asynchronous
           public void startBuild(){
              this.buildOutputSb = new StringBuffer();
      
              //Stimulating the build process , which will output the log message to the buildOutputSb
              for (int i = 0; i < ENTIRIES; i++) {
                  buildOutputSb.append("Output").append(i).append("<br/>");
                  try {
                      Thread.sleep(SLEEP_SEC);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              this.enablePolling = false;
          }
      }
      

       

      I would be happy for any suggestions...