如何使Primefaces Growl堆栈消息?

时间:2015-03-19 12:05:22

标签: jsf primefaces

CommandButton显示咆哮。但之前的咆哮信息已经丢失。如何使growl显示消息堆栈?

例如:

<h:form> 
    <p:growl id="growl" showDetail="true" life="6000" />  
    <p:commandButton value="Show" actionListener="#{growlView.showMessage}" update="growl" />  
</h:form>

和bean功能:

public void showMessage() {
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Hello"));
}

我每秒点按一次按钮。我希望消息将存储并显示6秒钟。 但点击按钮后,上一条消息隐藏,我只看到当前消息。

当我调试时,我有:

FacesContext.getCurrentInstance().getMessageList().size() == 0

我试过

FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);

<context-param>
    <param-name>org.primefaces.messagePersistence</param-name>
    <param-value>true</param-value>
</context-param>

但是不起作用=(

请帮忙

3 个答案:

答案 0 :(得分:4)

对于想要在同一p:growl中以堆栈方式显示消息而不隐藏先前消息的人,使用primefaces 5.1的简单解决方案是覆盖组件的默认行为,将primefacesFixes.js文件添加到使用下面的注释行覆盖类路径并覆盖该函数:

primefacesFixes.js:

PrimeFaces.widget.Growl.prototype.show = function(b) {
var a = this;
this.jq.css("z-index", ++PrimeFaces.zindex);
//this.removeAll(); //Commenting this line prevents an ajax update tho the <p:growl> from erasing global messages
$.each(b, function(c, d) {
    a.renderMessage(d);
});

};

所以你在你的模板标签上调用这样的修复文件:

<h:outputScript name="javascript/primefacesFixes.js" target="head" />

并且页面上只能使用一个p:growl来呈现所有需要的消息。

答案 1 :(得分:3)

不幸的是,这目前无法实现。实际上,这是2011年的默认行为(堆叠咆哮消息),但是主要核心团队决定:

  

在ajax update

上显示新消息之前隐藏先前的消息

来源:https://code.google.com/p/primefaces/issues/detail?id=1925

但是,创建了一个问题here(2014年10月)以恢复此功能,但尚未进行审核。

答案 2 :(得分:0)

将其发布在一个老问题上,但这可能是一个解决方案(尽管我使用的是PFv6.2):

<p:growl id="messages" showDetail="true" keepAlive="true"/>

只需将keepAlive="true"添加到咆哮元素。

相关问题