Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display growl when page is loaded primefaces jsf2

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

like image 726
begiPass Avatar asked May 14 '13 18:05

begiPass


1 Answers

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.
}
like image 184
BalusC Avatar answered Sep 28 '22 07:09

BalusC