无法更新"咆哮"在Backing bean的模板中

时间:2015-03-12 14:24:14

标签: jsf primefaces managed-bean growl requestcontext

我有一个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时,我认为应该显示;但不是,这是我的问题

0 个答案:

没有答案