简体   繁体   English

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

[英]How to implement a loading page in JSF 2.2

I want to implement a loading page like gmail in my JSF web Application. 我想在我的JSF Web应用程序中实现一个加载页面,例如gmail。

  1. User enters login and password i take him to a simple page with progress bar (loading Application Page ). 用户输入登录名和密码,然后进入带进度栏的简单页面(正在加载应用程序页面 )。
  2. once the progress bar hits 100% the Application page is shown. 一旦进度条达到100%,就会显示“应用程序”页面。

(hits 100% means that it gets progress value according to the progress of the initialization of the Application page ). (点击100%表示它会根据Application页面的初始化进度获得进度值)。

Now, what do i really need to implement this, backing beans scopes, number of facelets, faces-config.. 现在,我真正需要实现什么,支持bean范围,facelets数量,faces-config。

Additional info : 附加信息 :

  • i'm using Primefaces 4.0 我正在使用Primefaces 4.0
  • i'm using a WebFilter : 我正在使用WebFilter:

    @WebFilter(filterName = "AuthFilter", urlPatterns = {"*.xhtml"}) to redirect the not connecetd user to the login page. @WebFilter(filterName =“ AuthFilter”,urlPatterns = {“ * .xhtml”})可以将无关的用户重定向到登录页面。

在此处输入图片说明


This is what I've tried so far but no luck (the application stops in the loading page). 到目前为止,这是我尝试过的,但是没有运气(应用程序在加载页面中停止)。

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

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

loaderPage.xhtml no backing bean 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 <==this is located on the Application page backing bean (session scoped) dyna.progress <==它位于Application页面的后备bean(会话作用域)上

this is how i set the value on progress bar of loadingPage.xhtml 这是我在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;
         ...}

This is the faces-config 这是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>

Have a look at the solution Primefaces provides, namely ProgressBar . 看一下Primefaces提供的解决方案,即ProgressBar In your case I would not make the init() method @PostConstruct , I would call the init() method once the client is forwarded to the loaderPage.xhtml . 在您的情况下,我不会使用init()方法@PostConstruct ,一旦客户端转发到loaderPage.xhtml ,我会调用init()方法。 From there on you can call getProgress() . 从那里可以调用getProgress()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM