Jsfの進捗バーの使い方

13165 ワード

Jsfの進捗バーの使い方
フロントエンドページ
1 
2 3          value="#{ProjectPackageManageBackingBean.progress}" labelTemplate="{value}%"
4          styleClass="animated" global="false" id="pbAjax"   >
5         6              update=":form:message,:form:pbAjax,:form:shade" />
7     

バックエンドbeanレイヤロジック
  1     /**     **/
  2     private Integer progress = 0;
  3     
  4     public Integer getProgress()
  5     {
  6         if (progress == null)
  7         {
  8             progress = 0;
  9         }
 10         try 
 11         {
 12             Thread.sleep(1000);
 13         } catch (InterruptedException e) {
 14             e.printStackTrace();
 15         }
 16         if (progress == null)
 17         {
 18             progress = 0;
 19         }
 20         else 
 21         {
 22             progress = rateCalculate(progressSum, progressDo);
 23             
 24         if (progress >= 100)
 25              
 26             progress = 100;
 27         }
 28         return progress;
 29     }
 30 
 31     public void setProgress(Integer progress)
 32     {
 33         this.progress = progress;
 34     }
 35     //  
 36     public void onComplete()
 37     {
 38         //  
 39         progress = null;
 40         //  
 41         progressSum=null;
 42         //  
 43         progressDo=null;
 44     }
 45     private Integer progressSum;//  
 46     private Integer progressDo;//  
 47   
 48     public Integer getProgressSum()
 49     {
 50         return progressSum;
 51     }
 52      
 53     public void setProgressSum(Integer progressSum)
 54     {
 55         this.progressSum = progressSum;
 56     }
 57 
 58     public Integer getProgressDo()
 59     {
 60         return progressDo;
 61     }
 62 
 63     public void setProgressDo(Integer progressDo)
 64     {
 65         this.progressDo = progressDo;
 66     }
 67     //  
 68     public static Integer rateCalculate(Integer sum, Integer doSum)
 69     {
 70         if (sum == null)
 71         {
 72             return 0;
 73         }
 74         if (doSum == null)
 75         {
 76             return 0;
 77         }
 78         if (sum == 0 || doSum == 0)
 79         {
 80             return 0;
 81         }
 82         //     
 83         NumberFormat numberFormat = NumberFormat.getInstance();   
 84         //  2    
 85         numberFormat.setMaximumFractionDigits(2);   
 86         //  
 87         String result = numberFormat.format((float)doSum/(float)sum*100);
 88         //  . 
 89         int indexOf = result.indexOf(".");
 90         int parseInt = 0;
 91         //  
 92         if (indexOf==-1)
 93         {
 94             parseInt=Integer.parseInt(result);
 95         }
 96         else 
 97         {
 98             //  
 99             String substring = result.substring(0, indexOf);
100             //  
101             parseInt = Integer.parseInt(substring);
102         }
103         return parseInt;        
104     }

タスクのパーセンテージを計算すると、進捗バーはパーセンテージを監視し続け、パーセンテージに達すると、進捗バーの完了イベントがトリガーされ、進捗バーが空になり、最初の状態に戻ります.