I would like to use Mark Leusnik's (thanks to him) really nice ProgressBar implementation. Unfortunately the implementation doesn't work for me.
After some investigations, I found the reason for my troubles: In my xpage application, I have server page persistence setting keep pages in memory
. In Mark Leusnik's Demo App the setting is keep pages on disk
. I have no idea, why this setting has an impact on the runtime behavior of the progress bar?
All works fine with setting keep pages on disk
:
Unfortunately not with setting keep pages in memory
:
Thanks in advance for any solution, workaround or alternative!
After some further investigations, I have found a solution which works perfect independent of server page persistence settings (keep pages in memory/ keep pages on disk
).
The key point of my solution is the implemention of an additional XAgent for the serverside task, instead of running the code inside the onClick-Event
of the button. In addition, this XAgent will be "started" (dojo.xhrGet
) in the start routine of the progress bar.
On Mark Leusnik's solution I have done the following changes:
demo.xsp - XPage
<xp:button value="Start a (fake) long running process"
id="button1" dojoType="dijit.form.Button">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[xProgress.start();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
xProgress - Script Library (CSJS)
start : function() {
this.targetNode = dojo.byId(this.targetNodeId);
if (this.targetNode==0) {
alert("Invalid target node specified for xProgress progress bar");
}
//setup the dijit progressbar
if (this.progressBar == null) {
this.progressBar = new dijit.ProgressBar(
{id: "myProgressBar", maximum: 100}, this.targetNode);
} else {
this.progressBar.update({
maximum: 100,
progress: 0
});
}
dojo.xhrGet({
url: window.location.href.substring(0,
window.location.href.indexOf(".nsf")+4) + "/export.xsp",
load: dojo.hitch(xProgress, "stop")
});
this.timerId = setInterval( dojo.hitch(xProgress, "update"), this.updateInterval);
},
export.xsp - XAgent (the new one)
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false">
<xp:this.afterRenderResponse><![CDATA[#{javascript: print("long running code started");
print( "browser: " + context.getUserAgent().getBrowser() + ",
remote IP: " + facesContext.getExternalContext().getRequest().getRemoteAddr());
updateProgress(0);
/*java.lang.Thread.sleep(750);
updateProgress(5);
java.lang.Thread.sleep(750);
updateProgress(10);
java.lang.Thread.sleep(750);
updateProgress(15);
java.lang.Thread.sleep(750);
updateProgress(20);
java.lang.Thread.sleep(750);
updateProgress(25);
java.lang.Thread.sleep(750);
updateProgress(30);
java.lang.Thread.sleep(2000);
updateProgress(50);
java.lang.Thread.sleep(1500);
updateProgress(60);
java.lang.Thread.sleep(1500);
updateProgress(75);
java.lang.Thread.sleep(1500);
updateProgress(80);
java.lang.Thread.sleep(1500);
updateProgress(90);
java.lang.Thread.sleep(1500);
updateProgress(100);*/
print("long running code stopped");
function updateProgress(to) {
progressPercentage = to;
synchronized(sessionScope) {
sessionScope.put("progress", to);
}
}}]]></xp:this.afterRenderResponse>
</xp:view>