Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ADF Code Corder 42 : Using an <af:poll> with an Application Module

wlovettMar 9 2014 — edited Apr 4 2014

Hi All,

Using JDev 11.1.2.3.0.

I've been working on solving this puzzle for awhile.  I'm trying to implement a simpler version of ADF Code Corner #42 (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/42-progressbarcolor-169184.pdf

The trick is that my "business service" is running in my application module.  In a nutshell, I take 10,000 view object rows and run them through a few different algorithms.  It'd be great to give a progress report during this operation.  However, as soon as I start my application module method, my <af:poll> component shuts down, refusing to update the page in the process.

I've looked at alot of different tutorials/sites to try to fix this problem.  I'm trying to stay within the bounds of ADF Essentials which means no ADS, only polling.  Here are a couple of the better references:

GEBS | Oracle ADF Progress Indicator in Fusion Middleware 11g

Refresh part of the page periodically using poll component |

One page runs their "business service" in the managed bean and the other simply re-executes a view object.  I can't find a site which runs their own business service and polls during it.  Here's what I've got:

Application Module

    private long uploadStatus;


    public void doUpload() {
        long max = this.getMaximum();
        for(this.uploadStatus = 0; this.uploadStatus <= max ; this.uploadStatus += 500){
            System.out.println("@ " + this.uploadStatus);
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Upload Complete");
    }

    public long getStatus(){
        return this.uploadStatus;
    }

    public long getMaximum(){
        return 10000;
    }

Backing Bean

public class ProgressBarModel extends BoundedRangeModel {

    private long max;

    private long status;

    Thread newProgress = null;

    public ProgressBarModel() {

        this.getMaximum();

        this.getValue();

    }

    @Override

    public long getMaximum() {

        // Not best practice. Should get through page def method operation

        AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModule("AppModuleDataControl");

        this.max = am.getMaximum();

        return this.max;

    }

    @Override

    public long getValue() {

        System.out.println("polling ...");

        AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModule("AppModuleDataControl");

        this.status = am.getStatus();

        return this.status;

    }

    public void doUpload(ActionEvent actionEvent) {

        if (newProgress != null) {

            newProgress.interrupt();

        }

        ProgressUpdater progressSimulator = new ProgressUpdater();

        newProgress = new Thread(progressSimulator);

        newProgress.run();

    }

    public void stopUpload() {

        newProgress.interrupt();

        newProgress = null;

    }

    class ProgressUpdater implements Runnable {

        public void run() {

            AppModuleImpl am = (AppModuleImpl)ADFUtils.getApplicationModule("AppModuleDataControl");

            am.doUpload();

        }

    }

    public long getPercentageUploaded() {

        long state = this.status * 10 / 10000;

        if(state >= 100){

            this.stopUpload();

        }

        return this.status * 100 / 10000;

    }

}

JSPX

<af:panelFormLayout id="pfl1">

                                <af:poll id="pollid" interval="1000"/>

                                <af:outputFormatted value="#{MyProgressRangeModel.percentageUploaded}% completed"

                                                    id="of1" partialTriggers="pollid"/>

                                <af:commandToolbarButton actionListener="#{MyProgressRangeModel.doUpload}" text="Run"

                                                        id="ctb1"/>

</af:panelFormLayout>

Gives me the output

polling ...

polling ...

polling ...

@ 0

@ 500

@ 1000

@ 1500

@ 2000

@ 2500

@ 3000

.... // up to 10000

Upload Complete

polling ...

polling ...

How can I get the poll to monitor while an application module's method is running?  Use more than one app module, one for inserting into the database and another for monitoring?

Thanks,

Will

This post has been answered by wlovett on Apr 4 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2014
Added on Mar 9 2014
3 comments
214 views