31 Ekim 2013 Perşembe

Primefaces Growl Not Rendered After Update

I continue forwarding my experiences on primefaces. Today I've had another issue and finally got the solution.

If you are using primefaces growl component to show messages after a process, you have to add a FacesMessage to FacesContext and update the component or set globalOnly attribute true. Ordinarily, growl must show up and show your test you put in FacesMessage. In my project, I push a primefaces command button that has an actionListener, I do things in server side, put my FacesMessage to the context and update my components in UI. But the growl does not show up. I've searched for the problem and finally say my mistake got the solution.

Here is my problematic code:
<h:form id="formNewF">

  <p:dialog widgetVar="dlgNewF" dynamic="true">
    <p:ajax event="close" listener="#{myController.closeF()}" update="formNewF"/>
    
    <p:panelGrid columns="3" id="newFPanel">
      <h:outputLabel for="fName" value="FName" /> 
      <p:inputText id="fName" value="#{myController.newF.name}" /> 
      <p:message id="fNameMessage" for="fName" display="text" />  
      <p:column/>
      <p:commandButton value="Save" update="newFPanel, dataTable" action="#{myController.saveF()}" oncomplete="if(!args.validationFailed){dlgNewF.hide();}"/> 
      <p:column/>
    </p:panelGrid>
  </p:dialog>

</h:form>

As you can see, I execute my saveF method. In that method, I put my FacesMessage to context. Here the problem comes. When I return to xhtml the code updates dataTable but the code in my oncomplete event triggers an ajax event which means that we have to go to the server side again. Remember, these are all happening before rendering the xhtml. So my second request to server side overrides the previous context or creates a new one and deletes my FacesMessage. This is the reason why growl does not render.

As a summary, more than one request to server side before rendering the view causes disappearing your FacesMessage and the growl does not render. You can solve this problem by removig the second request or doing the job in one server side request.

( primefaces, jsf, growl, facesmessage, facescontext, rendering, twice, not shown )

Hiç yorum yok:

Yorum Gönder