0

I am using JSF 2.x and richfaces. I have following requirement to be implemented.

Please wait

This image describes that step1 is completed sucessfully, step2 is under progress and step3 is yet to be started.

I have following backing bean code

public void doAllSteps() {
   // set step1 flag started
   // do step1
   // set step1 flag success
   // set step2 flag under_progress
   // do step2
   // set step2 flag success
   // set step3 flag under_progress
   // do step3
   // set step 3 flag success
}

// There will be getters for all the flags

Now then in .xhtml page I did following

<a4j:poll id="poll" interval="1000" enabled="true" render="gr-img-status-panel" />

<a4j:outputPanel id="gr-img-status-panel">
    <div class="row mr-top1">
        <div class="col-xs-12">

            <h4 class="text-white text-left">
                Step 1
                <h:panelGroup rendered="#{myBean.step1Status eq 0}">
                    (Processing ...)
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step1Status eq 1}">
                    <span style="color: green;">&#x2714;</span>
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step1Status eq 2}">
                    <span style="color: red;">&#x2717;</span>
                </h:panelGroup>
            </h4>

            <h4 class="text-white text-left">
                Step 2 
                <h:panelGroup rendered="#{myBean.step2Status eq 0}">
                    (Processing ...)
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step2Status eq 1}">
                    <span style="color: green;">&#x2714;</span>
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step2Status eq 2}">
                    <span style="color: red;">&#x2717;</span>
                </h:panelGroup>
            </h4>

            <h4 class="text-white text-left">
                Step 3 
                <h:panelGroup rendered="#{myBean.step3Status eq 0}">
                    (Processing ...)
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step3Status eq 1}">
                    <span style="color: green;">&#x2714;</span>
                </h:panelGroup>
                <h:panelGroup rendered="#{myBean.step3Status eq 2}">
                    <span style="color: red;">&#x2717;</span>
                </h:panelGroup>
            </h4>

        </div>
    </div>
</a4j:outputPanel>

Also I have a a4j:commandButton where I execute the doAllSteps().

Problem

When 1st time I load the page a4j polling starts (it is fine for me). But as soon as I click the a4j:commandButton, the polling stops. After a4j:commandButton executed completely a4j polling start again. So it means that I cannot execute 2 a4j requests simultaneously.

How can I achieve my goal ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • try to let doAllSteps do the work in a new Thread, so it returns immediately – Turo May 24 '16 at 06:15
  • @Turo can you come-up with small example? –  May 24 '16 at 06:30
  • I'm very discouraged because BalusC edited your question but didn't leave an answer, maybe it isn't that easy... Here has someone a similar problem: http://stackoverflow.com/questions/8496806/long-running-task-in-java-ee-webapp-icefaces and here to: http://www.coderanch.com/t/214497/JSF/java/Command-Link-launch-long-proccess . Hope it helps – Turo May 24 '16 at 19:39
  • Just execute 3 ajaxes. Real async in JSF (and RF) is a mess. For me, it's not worth it. Also, running new Thread in this kind of apps is almost always a bad idea (you can check i.e.: http://stackoverflow.com/questions/6149919/is-it-safe-to-start-a-new-thread-in-a-jsf-managed-bean) – Emil Sierżęga May 25 '16 at 22:01

0 Answers0