adf学习:进度条的使用(progress bar demo)



adf学习:进度条的使用(progress bar demo).

背景:使用进度条progress bar显示数值比例,比例超过100%时,progress bar显示为红色,否则为蓝色
view层传递两个参数到back bean中,这两个参数分别为最大值和当前值,我在这里使用progress bar组件显示这两个数值的比例关系:
  1. <af:progressIndicator id=“pi1”
  2.      value=”#{pageFlowScope.incidentRequestControl.rangeModel
  3. (row.bindings.CurrentDuration.inputValue,row.bindings.MaxDuration.inputValue)}”
  4.      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代码:

  1. //获取样式,事先定义好样式名称,参考How-to dynamically change the progress bar color according to its current value
  2.     public String getProgressBarStyleClass(){
  3.         if (precent>=100){
  4.             progressBarStyleClass=”red_progress_bar”;
  5.         }
  6.         return progressBarStyleClass;
  7.     }
  8. //传入参数:当前值和最大值
  9.     public MyProgressRangeModel rangeModel(String duration, String maxDuration) {
  10.         MyProgressRangeModel rangeModel = new MyProgressRangeModel();
  11.         if (((“”.equals(maxDuration)) && ((“”.equals(duration)) && (duration != null) && (maxDuration != null)))) {
  12.             rangeModel.setMaximum(Long.parseLong(maxDuration));
  13.             rangeModel.setValue(Long.parseLong(duration));
  14.         }
  15.         return rangeModel;
  16.     }
  17. //progress bar值的获取需要继承BoundedRangeModel抽象类,详见API文档
  18.     private class MyProgressRangeModel extends BoundedRangeModel {
  19.         long maxValue=0L;
  20.         long currentValue=0L;
  21.         @Override
  22.         public long getMaximum() {
  23.             // TODO Implement this method
  24.             return maxValue;
  25.         }
  26.         @Override
  27.         public long getValue() {
  28.             // TODO Implement this method
  29.             return currentValue;
  30.         }
  31.         public void setMaximum(long maxValue){
  32.             this.maxValue=maxValue;
  33.         }
  34.         public void setValue(long currentValue){
  35.             this.currentValue=currentValue;
  36.         }
  37.     }
//获取样式,事先定义好样式名称,参考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文档:
相关博客: