我正在尝试使用 primefaces 对话框框架来简化我的代码。我已经按照 primefaces 4.0 用户指南中的示例进行操作,但它不起作用。
我几乎逐字复制了该示例,创建了三个文件:一个包含对话框的文件、一个调用对话框的文件和一个支持 bean 文件。
该对话框文件名为“dialog.xhtml”,位于“/Test”文件夹中,包含:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Cars</title>
</h:head>
<h:body>
Test dialog
</h:body>
</html>
基本文件名为“testDialog.xhtml”,位于“/Test”文件夹中,包含:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test Dialog</title>
<meta name="viewport" content="width=device-width"/>
</h:head>
<h:body>
<h:form>
<p:commandButton value="View Cars" actionListener="#{hostBean.view}" />
</h:form>
</h:body>
</html>
最后,支持 bean 包含:
@ManagedBean
@SessionScoped
public class HostBean implements Serializable {
public void view() {
RequestContext.getCurrentInstance().openDialog("/Test/dialog");
}
}
当我调试它时,视图被调用但对话框没有打开。 (我已将这三行添加到 faces-context 中。)
有任何想法吗?
我用这段代码让它工作:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;
@ManagedBean
@ViewScoped
public class HostBean implements Serializable {
public void view() {
RequestContext.getCurrentInstance().openDialog("dialog");
}
}
由于两个 xhtml 文件都位于同一文件夹(Test)中,因此您不需要使用“/Test/dialog”(如果您使用整个路径,则可以使其更加“全局”)。
Don't忘记将其添加到 faces-config.xml 中:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
</application>
</faces-config>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)