使用对话框框架的素面对话框未弹出 [英] primefaces dialog using dialog framework not popping up
问题描述
我正在尝试使用primefaces对话框框架来简化我的代码.我已经按照primefaces 4.0用户指南中的示例进行操作,但是该示例无法正常工作.
I'm trying to use primefaces dialog framework to simplify my code. I've followed the example in the primefaces 4.0 user guide and it's not working.
我几乎完全复制了该示例,创建了三个文件:一个包含对话框的文件,一个调用对话框的文件和一个后备bean文件.
I copied the example pretty much verbatim creating three files: a file with the dialog in it, a file that calls the dialog and a backing bean file.
该对话框文件名为"dialog.xhtml",位于"/Test"文件夹中,并且包含:
The dialog file is named "dialog.xhtml", is in the "/Test" folder and contains:
<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"文件夹中,并且包含:
The base file is named "testDialog.xhtml", is in the "/Test" folder and contains:
<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包含:
Finally, the backing bean contains:
@ManagedBean
@SessionScoped
public class HostBean implements Serializable {
public void view() {
RequestContext.getCurrentInstance().openDialog("/Test/dialog");
}
}
当我调试它时,将调用视图,但未打开对话框. (我将三行添加到faces-context中.)
When I debug it, view gets called but the dialog is not opened. (I have added the three lines to faces-context.)
有什么想法吗?
推荐答案
我使它可以使用以下代码:
I made it work with this code:
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/dialog"(如果使用整个路径,则可以使其更全局").
As both xhtml files are in the same folder (Test) you don't need to use "/Test/dialog" (you can make it more "global" if you use the whole path though).
不要忘记将其添加到您的faces-config.xml:
Don't forget to add this to your 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>
这篇关于使用对话框框架的素面对话框未弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!