如何打开保存在组件内的Primefaces Dialog?

时间:2015-01-13 13:45:28

标签: primefaces dialog

我正在尝试构建一个使用对话框进行某些操作的组件,我尝试按照Primefaces展示案例,当对话框在“客户端项目”中时,它工作正常,但当我将其移动到另一个项目时,因为.xhml文件不再出现在“客户端”,每次调用它时,我都应该开始获取一个nullpointer异常的框架。

以下是一些代码向您展示:

我的对话框叫做showClients.xhtml(只是一个简单的例子,不打扰你的业务逻辑)

<!DOCTYPE html>
<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>
    <style type="text/css">
.ui-widget {
    font-size: 90%;
}
</style>
</h:head>
<h:body>
    <p:outputLabel value="TESTE" />
</h:body>
</html>

在这里,我尝试从ManagedBean中调用它:

    Map<String,Object> options = new HashMap<String, Object>();
    options.put("modal", true);
    options.put("draggable", false);
    options.put("resizable", false);
    options.put("contentHeight", 320);

    RequestContext.getCurrentInstance().openDialog("showClients", options, null);

这就是我得到的:

1:44:24,047 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost/127.0.0.1:8080-5) java.lang.NullPointerException
    at org.primefaces.application.DialogNavigationHandler.handleNavigation(DialogNavigationHandler.java:47)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:129)
    at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
    at java.lang.Thread.run(Thread.java:744)

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您现在需要告诉JSF在哪里找到相对于WebContext的组件。因此,如果您的对话框showClients.xhtml文件位于WebContent / resources / myapp / mydialog等文件夹中,那么您将调用

RequestContext.getCurrentInstance().openDialog("/resources/myapp/mydialog/showClients", options, null);