jsf - Primefaces p :messages does not display

标签 jsf primefaces messages

您好,我在显示 p:messages 时遇到问题 我有这个页面:

<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>Facelet Title</title>
</h:head>
<h:body>
    <h:form prependId="false">  
        <p:messages id="msgs" showDetail="true"/>  
        <p:commandButton value="Info" actionListener="#{messagesController.addInfo}" update="msgs"/>  
        <p:commandButton value="Warn" actionListener="#{messagesController.addWarn}" update="msgs"/>  
        <p:commandButton value="Error" actionListener="#{messagesController.addError}" update="msgs"/>  
        <p:commandButton value="Fatal" actionListener="#{messagesController.addFatal}" update="msgs"/>  
    </h:form> 
</h:body>

这是我用来管理消息的bean

@ManagedBean(name = "beanMessageManager")
@SessionScoped
public class BeanMessageManager {    
    public void addInfo(ActionEvent actionEvent) {  
        FacesContext.getCurrentInstance().addMessage("form1:msgs", new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces rocks!"));  
    }   
    public void addWarn(ActionEvent actionEvent) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,"Sample warn message", "Watch out for PrimeFaces!"));  
    }    
    public void addError(ActionEvent actionEvent) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Sample error message", "PrimeFaces makes no mistakes"));  
    }  
    public void addFatal(ActionEvent actionEvent) {  
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Sample fatal message", "Fatal Error in System"));  
    }   
}

当我点击某个按钮时,没有显示消息。

我做错了什么?

非常感谢您的回复

最佳答案

看起来您在 actionListener 中的 bean 名称有误.

bean 名为 @ManagedBean(name = "beanMessageManager")但在 xhtml 页面中,您尝试调用 actionListener="#{messagesController.addInfo}" .

也许这行得通:

<p:commandButton value="Info" actionListener="#{beanMessageManager.addInfo}" update="msgs"/>  
<p:commandButton value="Warn" actionListener="#{beanMessageManager.addWarn}" update="msgs"/>  
<p:commandButton value="Error" actionListener="#{beanMessageManager.addError}" update="msgs"/>  
<p:commandButton value="Fatal" actionListener="#{beanMessageManager.addFatal}" update="msgs"/>

编辑
你也错过了 </html> xhtml 文件末尾的标记。另外我认为你应该使用 msgs而不是 "form1:msgs" .不幸的是,我不是 100% 确定 primefaces 是如何工作的,因为我从未使用过它。

关于jsf - Primefaces p :messages does not display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20494587/

相关文章:

primefaces - 刷新 p :schedule without changing the current view

objective-c - 如何编写具有多个参数的方法/消息?

jsf-2 - 如何将支持 bean 中的 FacesMessage 附加到 ui :repeat? 中的特定字段

windows - Delphi:如何响应WM_SettingChange/WM_WinIniChange?

jsf - 如何在 JSF panelGrid 中设置 colspan 和 rowspan?

jsf - Init 方法在@Viewscoped bean 中被调用两次

命令按钮上的 JSF 导航

java - PrimeFaces DataTable - 过滤(运行示例的问题)

java - 如何使用RichFaces a4j :commandButton not using submit

jsf - 如何以编程方式配置 dataTable 的 rowSelect 事件监听器