如何在JSF 2.2中实现加载页面

时间:2014-03-24 17:20:45

标签: java jsf jsf-2 primefaces

我想在我的JSF网络应用程序中实现像gmail一样的加载页面

  1. 用户输入登录名和密码后,我将他带到一个简单页面,其中包含进度条(加载应用程序页面)。
  2. 一旦进度条达到100%,将显示“应用程序”页面。
  3. (点击100%意味着它根据应用程序页面的初始化进度获得进度值。)

    现在,我真正需要实现这一点,支持bean范围,facelets数量,faces-config ..

    其他信息:

    • 我正在使用Primefaces 4.0
    • 我正在使用WebFilter:

      @WebFilter(filterName =“AuthFilter”,urlPatterns = {“* .xhtml”})将not connecetd用户重定向到登录页面。

    enter image description here


    这是我到目前为止所尝试但没有运气(应用程序在加载页面中停止)。

    login.xhtml 支持bean userBean(会话作用域)。

    userBean.doLogin()  ==> return "loaderPage";
    

    loaderPage.xhtml 没有支持bean

    <h:body>
        <p:progressBar widgetVar="pbAjax" ajax="true"
                       value="#{dyna.progress}"
                       labelTemplate="{value}%"
                       styleClass="animated">  
            <p:ajax event="complete" listener="#{userBean.onComplete}" />  
        </p:progressBar>  
    </h:body>
    

    dyna.progress&lt; ==这位于应用程序页面支持bean(会话作用域)

    这就是我在 loadingPage.xhtml

    的进度条上设置值的方法
    @ManagedBean(name = "dyna", eager = true)
    @SessionScoped
    @PostConstruct
    public void init() {
        try {
            progress = 0;
            etatdateOptions = ListsMaker.getDateFilters();
            progress = 10;
            optionspatState = ListsMaker.getPatientStates();
            progress = 20;
            optionsCotpatState = ListsMaker.getPayementStates();
            progress = 30;
             ...}
    

    这是faces-config

    <faces-config version="2.2"
              xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_2.xsd">
    
    <navigation-rule>
        <from-view-id>/loader.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{userBean.oncomplete}</from-action>
            <to-view-id>/AppPlace.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>
    
    <navigation-rule>
        <from-view-id>/AppPlace.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{dyna.killView}</from-action>
            <from-outcome>success</from-outcome>
              <to-view-id>/login.xhtml</to-view-id>
               <redirect>     
               </redirect>
           </navigation-case>
       </navigation-rule>
    

1 个答案:

答案 0 :(得分:0)

查看Primefaces提供的解决方案,即ProgressBar。在您的情况下,我不会使用init()方法@PostConstruct,我会在客户端转发到init()后调用loaderPage.xhtml方法。从那里开始,您可以拨打getProgress()