【问题标题】:Block entire page阻止整个页面
【发布时间】:2014-12-05 22:16:16
【问题描述】:

当我更改页面(page1 到 page2)时存在一些延迟,并且可以单击其他按钮并且这些操作会运行。所以我想在等待加载下一个页面的过程中阻塞页面,我该怎么做?

我使用 jsf2 和 primefaces。

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

【问题讨论】:

  • 您介意给我们一些代码吗?你试过这个stackoverflow.com/questions/20198898/… 吗?
  • 此时已经测试过blockUI和blockUI-extensions -> 不工作
  • 这里的重点是当存在一个在两个页面之间移动时如何阻止页面
  • 代码是这样的:存在一个页面,一个按钮,这个按钮有一个到页面2的链接
  • “不工作”不是问题描述。它怎么不工作?

标签: jsf-2 primefaces primefaces-mobile


【解决方案1】:

你应该告诉我们。为什么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();
        }
    }
}

【讨论】:

  • 你有理由。一定是分心了:\谢谢
猜你喜欢
  • 2022-07-09
  • 2016-05-08
  • 2010-10-18
  • 1970-01-01
  • 2013-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多