FacesContext.addMessage()不在p:消息中显示消息

时间:2016-02-17 15:04:41

标签: jsf primefaces jboss facescontext

我有一个托管bean,其方法可以添加如下消息:

@ManagedBean
@ViewScoped
public class FileMB implements Serializable{

private static final long serialVersionUID = -2843716026642626725L;

private UploadedFile file;
private boolean enabled = false;

public UploadedFile getFile() {
    return file;
}

public void setFile(UploadedFile file) {
    this.file = file;
}

public void upload() {

    FacesMessage message = new FacesMessage("test");
    FacesContext.getCurrentInstance().addMessage(null, message);

}

我从xhtml调用此方法:

<!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:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:p="http://primefaces.org/ui">
<h:head>
    <title></title>
</h:head>
<h:body>
<h:form>
    <p:commandButton value="Show" type="button" actionListener="#{fileMB.upload}" />
</h:form>
 <h:form id="frmMensajes">
    <p:messages id="mensajes" showDetails="false"/>
</h:form>
</h:body>
</html>

但我看不到“测试”消息,我也在faces-config中添加了托管bean声明,我该怎么办?

2 个答案:

答案 0 :(得分:0)

尝试添加delegate属性。

这样的事情:tableView

根据文件:

  

启用自动更新后,将自动使用每个ajax请求更新消息组件

答案 1 :(得分:-1)

在第一个h:form

中尝试以下其中一项

1)p:messages globalOnly="true"

2)p:message for=<command button id>并将id添加到commanbutton

相关问题