2014-10-10 68 views
1

當我更改頁面(頁面1到頁面2)時存在一些延遲,並且可以單擊其他按鈕並執行這些操作。所以我想在加載下面這個頁面的等待時間內阻止頁面,我該怎麼辦?阻止整個頁面

我使用jsf2和primefaces。

此時已經測試blockUI和blockUI的擴展 - >不行

+0

你介意給我們提供一些代碼?你有沒有試過這個http://stackoverflow.com/questions/20198898/how-to-target-entire-jsf-page-to-be-blocked-by-pblockui-peblockui? – Leo 2014-10-10 17:12:10

+1

此時已經測試過blockUI和blockUI-extensions - >不行 – Marin 2014-10-10 17:14:42

+1

這裏關注的是如何在頁面存在兩頁之間時移動頁面 – Marin 2014-10-10 17:16:49

回答

4

你應該告訴我們。爲什麼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(); 
     } 
    } 
} 
+2

你有理由。必須分心:\謝謝 – Marin 2014-10-13 09:21:26