![](/img/trans.png)
[英]Primefaces DialogFramework Growl and showMessageInDialog not working
[英]Primefaces : how to use growl for notifications without user interaction
我是JSF / Primefaces的新手,所以也许我错误地解决了这个问题而且我一直在搜索论坛,但没有运气。
我将问题简化为最大值并使用了Damian的@PostConstruct
所以要恢复我希望在加载test.xhtml时,我的咆哮通知会弹出 - 即没有用户交互 ...而且它没有显示,但是当你点击保存按钮时它会显示。
它确实通过sayHi()但似乎并不知道那个时候的容器。
WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
目标是在数据库访问失败时使用growl显示用户友好的通知。
我必须错过一些我相信的基本原则:(
<h:form id="form">
<p:growl id="growl" showDetail="true" showSummary="true" sticky="true" />
<h:outputLabel value="#{testGrowl.message}" />
<p:commandButton value="Save" actionListener="#{testGrowl.save}" update="growl" />
</h:form>
@ManagedBean
public class TestGrowl {
private String message;
public TestGrowl()
{
//sayHi(); commented to try with @PostConstruct
message = "we've been in the TestGrowl constructor";
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void save(ActionEvent actionEvent) {
sayHi();
}
@PostConstruct
private void sayHi(){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful", "Hello "));
}
}
非常感谢
有可能的。 当消息添加到bean的构造函数@PostConstruct或preRenderView监听器上时,它会自动显示在页面上,您不必使用任何“onload”事件。 代码的问题在于您没有正确发送消息。 这是你应该这样做的:
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "test", "test");
FacesContext.getCurrentInstance().addMessage(null, msg);
addMessage的第一个参数是有错误的组件的ID,如果是全局错误,则为null。 此外,如果在您的咆哮中您只想显示全局消息,并且您希望仅为每个组件使用p:message显示特定于组件的错误消息,则应将globalOnly="true"
添加到growl。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.