开发环境:JDeveloper 11.1.2.0.0。
说明:本文改自本人旧作,使用了目前最新的JDeveloper 11.1.2.0.0重新开发验证。(2011-8-4)
1. 页面代码
原理说明:
(1)Poll组件每隔interval(单位毫秒,-1表示停止)指定时间,调用pollListener方法一次。
(2)ProgressIndicator组件的partialTriggers指向Poll组件,这样pollListener每执行一次,ProgressIndicator组件就刷新一次。从视觉上看,就好像进度条在前进一样。
(3)Poll进度条组件必须使用viewScope的Managed Bean。
(4)注意ProgressIndicator组件的visible属性使用了EL动态设置。
<af:form id="f1">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:commandButton text="Start Poll" id="cb1" partialSubmit="true"
actionListener="#{viewScope.myBackingBean.startButton_actionListener}"/>
<af:separator id="s1"/>
<af:commandButton text="Stop Poll" id="cb2" partialSubmit="true"
actionListener="#{viewScope.myBackingBean.stopButton_actionListener}"/>
</af:panelGroupLayout>
<af:poll id="pol1" interval="-1" pollListener="#{viewScope.myBackingBean.poll_listener}"
partialTriggers="cb1 cb2" binding="#{viewScope.myBackingBean.pollComponent}"/>
<af:progressIndicator id="pi1" partialTriggers="pol1"
value="#{viewScope.myBackingBean.myProgressRangeModel}" rendered="true"
visible="#{viewScope.myBackingBean.myProgressRangeModel.value > 0 and viewScope.myBackingBean.myProgressRangeModel.value <viewScope.myBackingBean.myProgressRangeModel.maximum }"/>
</af:form>
2. Managed Bean代码
public void poll_listener(PollEvent pollEvent) {
long value = myProgressRangeModel.getValue();
long count = value + stepPace;
if (count <= maxValue) {
myProgressRangeModel.setValue(count);
} else {
stopPoll();
}
}
public void startButton_actionListener(ActionEvent actionEvent) {
startPoll();
}
public void stopButton_actionListener(ActionEvent actionEvent) {
stopPoll();
}
public void startPoll() {
pollComponent.setInterval(1000);
AdfFacesContext.getCurrentInstance().addPartialTarget(pollComponent);
}
public void stopPoll() {
pollComponent.setInterval(-1);
AdfFacesContext.getCurrentInstance().addPartialTarget(pollComponent);
}
3. 运行页面
Project下载:MyProgressIndicator.7z。
参考文献:
1. http://groundside.com/blog/DuncanMills.php?title=the_progress_indicator&more=1&c=1&tb=1&pb=1
2. http://gergerconsulting.blogspot.com/2007/04/adf-faces-progressindicator-example-for.html
3. http://www.gebs.ro/blog/oracle/adf-progress-indicator-in-fusion-middleware-11g/
4. http://jobinesh.blogspot.com/2010/08/example.html
5. http://hi.baidu.com/ganyu21/blog/item/a8baf31f07ac09f5e0fe0bbd.html
没有评论:
发表评论