adf学习:进度条的使用(progress bar demo).
背景:使用进度条progress bar显示数值比例,比例超过100%时,progress bar显示为红色,否则为蓝色
view层传递两个参数到back bean中,这两个参数分别为最大值和当前值,我在这里使用progress bar组件显示这两个数值的比例关系:
- <af:progressIndicator id=“pi1”
- value=”#{pageFlowScope.incidentRequestControl.rangeModel
- (row.bindings.CurrentDuration.inputValue,row.bindings.MaxDuration.inputValue)}”
- styleClass=”#{pageFlowScope.incidentRequestControl.progressBarStyleClass}”/>
<af:progressIndicator id=“pi1” value="#{pageFlowScope.incidentRequestControl.rangeModel (row.bindings.CurrentDuration.inputValue,row.bindings.MaxDuration.inputValue)}" styleClass="#{pageFlowScope.incidentRequestControl.progressBarStyleClass}"/>
back bean代码:
- //获取样式,事先定义好样式名称,参考How-to dynamically change the progress bar color according to its current value
- public String getProgressBarStyleClass(){
- if (precent>=100){
- progressBarStyleClass=”red_progress_bar”;
- }
- return progressBarStyleClass;
- }
- //传入参数:当前值和最大值
- public MyProgressRangeModel rangeModel(String duration, String maxDuration) {
- MyProgressRangeModel rangeModel = new MyProgressRangeModel();
- if (((“”.equals(maxDuration)) && ((“”.equals(duration)) && (duration != null) && (maxDuration != null)))) {
- rangeModel.setMaximum(Long.parseLong(maxDuration));
- rangeModel.setValue(Long.parseLong(duration));
- }
- return rangeModel;
- }
- //progress bar值的获取需要继承BoundedRangeModel抽象类,详见API文档
- private class MyProgressRangeModel extends BoundedRangeModel {
- long maxValue=0L;
- long currentValue=0L;
- @Override
- public long getMaximum() {
- // TODO Implement this method
- return maxValue;
- }
- @Override
- public long getValue() {
- // TODO Implement this method
- return currentValue;
- }
- public void setMaximum(long maxValue){
- this.maxValue=maxValue;
- }
- public void setValue(long currentValue){
- this.currentValue=currentValue;
- }
- }
//获取样式,事先定义好样式名称,参考How-to dynamically change the progress bar color according to its current value public String getProgressBarStyleClass(){ if (precent>=100){ progressBarStyleClass="red_progress_bar"; } return progressBarStyleClass; } //传入参数:当前值和最大值 public MyProgressRangeModel rangeModel(String duration, String maxDuration) { MyProgressRangeModel rangeModel = new MyProgressRangeModel(); if ((("".equals(maxDuration)) && (("".equals(duration)) && (duration != null) && (maxDuration != null)))) { rangeModel.setMaximum(Long.parseLong(maxDuration)); rangeModel.setValue(Long.parseLong(duration)); } return rangeModel; } //progress bar值的获取需要继承BoundedRangeModel抽象类,详见API文档 private class MyProgressRangeModel extends BoundedRangeModel { long maxValue=0L; long currentValue=0L; @Override public long getMaximum() { // TODO Implement this method return maxValue; } @Override public long getValue() { // TODO Implement this method return currentValue; } public void setMaximum(long maxValue){ this.maxValue=maxValue; } public void setValue(long currentValue){ this.currentValue=currentValue; } }
final result:
参考文档:
API文档:
相关博客: