Primefaces:首次访问时不显示对话框中的全局消息

时间:2014-07-14 17:14:15

标签: jsf jsf-2 primefaces

我试图在主窗体和对话框中显示globalMessage。对话框中的消息仅显示第二次打开对话框的时间。

我无法让它发挥作用。有人能解决这个问题吗?我真的很感激!

我正在使用JSF Mojarra 2.2.1,Primefaces 4.0和Apache Tomcat 7.0。

这是我的观点(testView.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:f="http://java.sun.com/jsf/core" 
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:p="http://primefaces.org/ui">

<h:head></h:head>

<h:body>
    <h:form id="testForm">
        <p:messages globalOnly="true" showDetail="true" closable="true" />
        <p:commandButton value="ClickMe" action="#{testBean.displayMessage()}" 
            update="testForm :testDialogForm" oncomplete="PF('testDialog').show()" />
    </h:form>

    <p:dialog id="testDialogId" widgetVar="testDialog" 
        dynamic="true" closable="true" closeOnEscape="true"
        header="Dialog with message">
        <h:form id="testDialogForm">
            <p:messages globalOnly="true" showDetail="true" closable="true" />
            <h:outputText value="This outputText should not be alone." />
        </h:form>
    </p:dialog>
</h:body>

这是我的bean(TestBean.java):

package de.simply.local.tbx.webbeans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name = "testBean")
@ViewScoped
public class TestBean {

    public void displayMessage() {

        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO,
                        "This is the summary.", "These are the details."));
    }

}

0 个答案:

没有答案