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 mygrowl
in the template file. - When
growl
is updated, I believe it should get displayed; but is not, which is my problem