zoukankan      html  css  js  c++  java
  • Jsf中进度条的用法

    Jsf中进度条的用法

    前端页面

    1 <!-- 进度条 -->
    2 <p:progressBar widgetVar="pbAjax" ajax="true"
    3          value="#{ProjectPackageManageBackingBean.progress}" labelTemplate="{value}%"
    4          styleClass="animated" global="false" id="pbAjax"   >
    5         <p:ajax event="complete" listener="#{ProjectPackageManageBackingBean.onComplete}"
    6              update=":form:message,:form:pbAjax,:form:shade" />
    7 </p:progressBar>    

    后端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     }

    通过计算任务的百分比,进度条会一直监听百分比,当达到百分百后,会触发进度条的完成事件,并将进度条置空,回到最初状态。

  • 相关阅读:
    【转】内部Handler类引起内存泄露
    检测是否存在相机硬件代码
    asp.net 过滤器
    iis 中经典和集成模式对应webconfig节点
    事务
    C# Excel操作
    一步一步部署SSIS包图解教程
    js和.net操作Cookie遇到的问题
    File,FileInfo,Directory,DirectoryInfo
    C#文件Copy
  • 原文地址:https://www.cnblogs.com/zyfBlogShare/p/12053201.html
Copyright © 2011-2022 走看看