来自bean的Primefaces对话框只显示一次

dic*_*c19 5 jsf primefaces jsf-2 glassfish-4

我正试图从这个PrimeFaces ShowCase中描述的bean中显示一个对话框.事情是一切按预期工作,对话框显示,但如果我关闭对话框然后再次按下按钮,除非页面刷新,否则对话框不会显示.

这不是示例中显示的行为,每次按下按钮时,对话框都会出现.

我在代码中唯一的区别是我使用了CDI替代品而不是托管bean包,因为javax.faces.bean包将被弃用.我的意思是:

  • javax.inject.Named 代替 javax.faces.bean.ManagedBean
  • javax.faces.view.ViewScoped 代替 javax.faces.bean.ViewScoped

在任何情况下,我也尝试过托管bean包,但仍然是相同的错误行为.

这是我到目前为止:

的index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form>
            <p:commandButton value="Open" actionListener="#{viewDialogMB.viewDialog()}"/>
        </h:form>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

ViewDialogMB.java

import java.util.HashMap;
import java.util.Map;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.context.RequestContext;


@Named(value = "viewDialogMB")
@ViewScoped
public class ViewDialogMB {

    public void viewDialog() {
        Map<String,Object> options = new HashMap<>();
        options.put("modal", true);
        options.put("resizable", true);

        RequestContext.getCurrentInstance().openDialog("dialog", options, null);
    }

}
Run Code Online (Sandbox Code Playgroud)

dialog.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Dialog Title</title>
    </h:head>
    <h:body>
        <p:outputLabel value="Hello from Dialog!" />
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

faces-config.xml(根据Dialog Framework文档)

<?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>
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我的平台(如果有任何区别)是:

  • Glassfish 4
  • JSF 2.2
  • JDK 1.7 - 64位
  • Java EE 7
  • PrimeFaces 5.0(社区版)

我尝试过使用Mozilla Firefox,Google Chrome和MS IE11.

小智 5

此错误在此处报告PF 4.0.10及更高版本中的对话框架回归错误问题6915:关闭从DataTable打开的DF窗口时PF 5.0错误

作为一种解决方案,使用taconic的解决方案,即在体内添加面板.

你的dialog.xhtml看起来像这样:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Dialog Title</title>
    </h:head>
    <h:body>
    <p:panel>
        <p:outputLabel value="Hello from Dialog!" />
     </p:panel>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)