0

我有一个托管 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 声明,我该怎么办?

4

2 回答 2

1

尝试添加autoUpdate属性。

像这样的东西:<p:messages id="mensajes" showDetails="false" autoUpdate="true" />

根据文档:

启用自动更新后,消息组件会随着每个 ajax 请求自动更新

于 2016-02-17T15:25:23.990 回答
-1

在第一个里面尝试以下之一h:form

1)p:messages globalOnly="true"

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

于 2016-02-17T16:02:20.310 回答