0

I have a template file which contains primefaces growl component. I am using this template in another index.xhtml file. Now I am trying to add a FacesMessage from backing bean in @postconstruct function. However my index.xhtml file is not showing the growl.

template.xhtml

       <div id="content-wrapper">
            <div id="content" class="template-00-startpage clearfix">                  
                <p:growl id="growl" showDetail="true" sticky="true" />             
            </div>
        </div>

index.xhtml

<h:body>
    <ui:composition template="/templates/Template.xhtml">
        <ui:define name="leftContent">
            <h:outputText value="#{backingBean.username}"></h:outputText>
        </ui:define>
    </ui:composition>
</h:body>

backingBean.java

@PostConstruct
private void init(){
    username = "testing it";
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "Trying to display this message");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.update("growl");      
}

I tried wrapping the <p:growl> component in <h:form id="main"> and then update main:growl, however it does not work.

I am not understanding what I am doing wrong. Is it necessary to trigger or update growl in .xhtml file or via commandButton update="growl"?

EDIT: My requirement is to use growl to display error messages. Therefore I am using it in template and can update it from any backing bean. The way I am trying to implement it is,

  • Have growl in template. It will get processed before backing bean. Hence will not be displayed.
  • An error occured, I will add that error message in FacesMessage and update my growl in the template file.
  • When growl is updated, I believe it should get displayed; but is not, which is my problem
Ankit
  • 1,075
  • 1
  • 8
  • 19
  • Maybe similar to this http://stackoverflow.com/questions/10197277/how-can-i-add-faces-messages-during-postconstruct Try adding `` You can also find some information here http://forum.primefaces.org/viewtopic.php?f=3&t=37142 – Mathieu Castets Mar 12 '15 at 14:33
  • @MathieuCastets Thanks for the links.....I have read the link... if I move my `growl` after the `h:outputText` it renders `growl`. However, I understand that my `growl` is getting processed before my managed bean, that is why I am trying to update the `growl` again in my backing bean. So if I am updating `growl` in backing bean, i guess it should be displayed or I am wrong? – Ankit Mar 12 '15 at 14:53

0 Answers0