我有一个template
文件,其中包含primefaces growl
组件。我在另一个template
文件中使用此index.xhtml
。现在,我尝试在FacesMessage
函数的backing bean
中添加@postconstruct
。但是,我的index.xhtml
文件未显示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");
}
我尝试在<p:growl>
中包装<h:form id="main">
组件,然后更新main:growl
,但它不起作用。
我不明白我做错了什么。是否有必要在growl
文件中或通过.xhtml
触发或更新commandButton update="growl"
?
编辑:我的要求是使用growl
来显示错误消息。因此我在模板中使用它,可以从任何支持bean更新它。我试图实现它的方式是,
growl
。它会在支持bean之前得到处理。因此不会显示。FacesMessage
中添加该错误消息,并在模板文件中更新我的growl
。growl
时,我认为应该显示;但不是,这是我的问题