阻止整个页面

时间:2014-10-10 17:07:35

标签: jsf-2 primefaces primefaces-mobile

当我更改页面(第1页到第2页)时存在一些延迟,可以单击其他按钮并运行这些操作。所以我想在加载下一页的等待时间内阻止页面,我该怎么做?

我使用jsf2和primefaces。

此时已经测试过blockUI和blockUI-extensions - >不工作

1 个答案:

答案 0 :(得分:6)

你应该告诉我们。为什么p:blockUI不起作用?

试试这个。这是工作。

page1.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <f:facet name="first">
            <meta http-equiv="Content-Type" 
                  content="text/html; charset=UTF-8" />
            <meta name="viewport" 
                  content="user-scalable=no, 
                  width=device-width, 
                  initial-scale=1.0, 
                  maximum-scale=1.0"/>
        </f:facet>

        <title>page1</title>
    </h:head>

    <h:body id="bodyView">
        page1
        <h:form id="form1">
            <p:editor id="editor" 
                      widgetVar="editorWidget" 
                      width="600" />
        </h:form>
        <h:form id="form2">
            <p:blockUI block=":bodyView" 
                       widgetVar="bui"/>
            <p:commandButton id="redirect" 
                             value="go to page2" 
                             onclick="PF('bui').show();"
                             actionListener="#{blockView.redirect}"/>
        </h:form>
    </h:body>
</html>

page2.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <f:facet name="first">
            <meta http-equiv="Content-Type" 
                  content="text/html; charset=UTF-8" />
            <meta name="viewport" 
                  content="user-scalable=no, 
                  width=device-width, 
                  initial-scale=1.0, 
                  maximum-scale=1.0"/>
        </f:facet>

        <title>page2</title>
    </h:head>

    <h:body>
        <h:form>
            page2
        </h:form>
    </h:body>
</html>

MangedBean

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Wittakarn
 */
@ViewScoped
@ManagedBean(name = "blockView")
public class BlockView implements Serializable{
    public void redirect(ActionEvent event){
        try {
            Thread.sleep(4000);
            FacesContext.getCurrentInstance().getExternalContext().redirect("page2.xhtml");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}