【问题标题】:How to draw a progress bar in JSF application如何在 JSF 应用程序中绘制进度条
【发布时间】:2013-10-11 10:40:01
【问题描述】:

我们有一个基于 JEE6 (JSF 2/ EJB 3 / Jboss 7) 构建的 Web 应用程序。

我们需要在我们的应用程序中显示如下所示的进度条。我们可以使用哪个框架?有没有办法在 Primefaces 中做这件事?

【问题讨论】:

    标签: jsf-2 primefaces progress-bar


    【解决方案1】:

    使用 PrimeFaces 的<p:progressBar/>。他们的showcase 有客户端、ajax 和静态版本的示例。

    ajax 版本归结为在某个操作上启动进度条(示例中的命令按钮单击)。当达到 100% 时它会自动停止(如果需要,会触发一个 ajax 事件,请参阅文档)

    展示柜的相关 xhtml 和 bean 部分(几乎)逐字复制

    xhtml

    <p:progressBar widgetVar="pbAjax" ajax="true" value="#{progressBarView.progress}" labelTemplate="{value}%" styleClass="animated" global="false">
        <p:ajax event="complete" listener="#{progressBarView.onComplete}" update="growl" oncomplete="PF('startButton2').enable()"/>
    </p:progressBar>
    

    @Named
    @ViewScoped
    public class ProgressBarView implements Serializable {
    
        private Integer progress;
    
        public Integer getProgress() {
            if(progress == null) {
                progress = 0;
            }
            else {
                progress = progress + (int)(Math.random() * 35);
    
                if(progress > 100)
                    progress = 100;
            }
    
            return progress;
        }
    
        public void setProgress(Integer progress) {
            this.progress = progress;
        }
    
        public void onComplete() {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Progress Completed"));
        }
    }
    

    在 PF 展示的示例中,您也可以取消它,但取消真正的服务器端操作超出了此处的范围,因此我将其删除:

    【讨论】:

    • @16num:PF 展示上有一个示例... 很容易找到(您可以通过按下其下方的编辑按钮提出编辑以回答)这就是“链接”的具体原因强烈反对“只回答”
    猜你喜欢
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2011-10-01
    相关资源
    最近更新 更多