ProgressIndicator组件使用指南之二:彩色进度条

1. 页面代码:my_progress_indicator2.jspx








actionListener="#{viewScope.myBackingBean2.progressIndicator_actionListener}" value="#{viewScope.myBackingBean2.myProgressRangeModel2}"/>


2. 为了显示颜色,使用了CSS,创建sample.css。

.red af|progressIndicator::determinate-filled-icon-style {
background-image: url("../../images/redbar.png");
}

.yellow af|progressIndicator::determinate-filled-icon-style {
background-image: url("../../images/yellowbar.png");
}

.green af|progressIndicator::determinate-filled-icon-style {
background-image: url("../../images/greenbar.png");
}

3. 创建trinidad-skins.xml,指向sample.css。



sample.desktop
sample
org.apache.myfaces.trinidad.desktop
fusion.desktop
skins/sample/sample.css



4. Managed Bean代码
public void startButton_actionListener(ActionEvent actionEvent) {
startPoll(actionEvent);
}

public void stopButton_actionListener(ActionEvent actionEvent) {
stopPoll(actionEvent);
}

public void progressIndicator_actionListener(ActionEvent actionEvent) {
stopPoll(actionEvent);
}

public void startPoll(ActionEvent actionEvent) {
// pollComponent.setRendered(true);
pollComponent.setInterval(1000);
//AdfFacesContext.getCurrentInstance().addPartialTarget(pollComponent);
myProgressRangeModel2.start(actionEvent);
}

public void stopPoll(ActionEvent actionEvent) {
//pollComponent.setRendered(false);
pollComponent.setInterval(-1);
//AdfFacesContext.getCurrentInstance().addPartialTarget(pollComponent);
myProgressRangeModel2.stop(actionEvent);
}

5. MyProgressRangeModel2.java代码
其最核心的是内部类:ProgressSimulator,该类模拟一个比较耗时业务服务操作。
该类支持多线程,这样就可以运行在另一个线程中,不用等待Managed Bean的方法返回。
这是一个很好的设计:让耗时的业务服务单独启用一个线程,并且使用进度条对用户友好提示。

//Simulate a business service progress
class ProgressSimulator implements Runnable {
public void run() {
try {
//stop fag is true if it is set to true or if value is equals or greater than maximum
stopFlag = stopFlag == true ? true : (getValue() < getMaximum() ? false : true);
//run in loop until stop condition is met. Make sure system doesn't
//fail if values are initially set to the same value
while (!stopFlag && getValue() != getMaximum()) {
Thread.sleep(1000);
setValue(getValue() + stepPace);
//set the color boundaries
if (getValue() >= greenBoundary) {
styleClass = GREEN;
} else if (getValue() >= yellowBoundary) {
styleClass = YELLOW;
} else {
styleClass = RED;
}

if (getValue() == getMaximum()) {
stopFlag = true;
}
}
//stop thread
newProgress.interrupt();
newProgress = null;
} catch (Exception exc) {
exc.printStackTrace();
}
}
}

6. 运行页面






Project下载: MyProgressIndicator2.7z

参考文献:
1. http://www.oracle.com/technetwork/developer-tools/adf/learnmore/42-progressbarcolor-169184.pdf

2. http://forums.oracle.com/forums/thread.jspa?threadID=999826

http://maping930883.blogspot.com/2011/08/adf105progressindicator.html

你可能感兴趣的:(ADF,马平ADF)