display growl when page is loaded primefaces jsf2

自闭症网瘾萝莉.ら 提交于 2019-12-12 12:26:03

问题


I have this commandButton :

    <p:commandButton value="Enregistrer" action="#{reglementClientMB.ajouter}" 
            process="@this @form" update="@form" >
            <f:setPropertyActionListener target="#{reglementClientMB.est_ajouter}" value="false" />
            </p:commandButton>

the action method return to another page , I want to display one p:growl when the next page is loaded

I tested to put that is the constructor of its managed bean but the growl is displayed below data in the page

FacesContext.getCurrentInstance().addMessage(
                        null,
                        new FacesMessage(FacesMessage.SEVERITY_INFO, ""
                                + "Confirmation", "Réglement crée avec sucée"));

                RequestContext.getCurrentInstance().update("messages");

how can I achieve this

thank you in advance


回答1:


The bean's constructor may be too late for the job if the <p:growl> is rendered before the bean is been constructed for the first time. E.g.

<p:growl />
...
<h:outputText value="#{bean.something}" />

It would only work if the bean is constructed before the <p:growl> is rendered.

<h:outputText value="#{bean.something}" />
...
<p:growl />

In order to solve your concrete problem, you'd need to do the job in a pre render view listener instead.

<f:event type="preRenderView" listener="#{bean.init}" />

With:

public void init() {
    // Add the desired message here.
}


来源:https://stackoverflow.com/questions/16550545/display-growl-when-page-is-loaded-primefaces-jsf2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!