How to Call p:growl from JavaScript in JSF?

In JSF p:growl is the component used to display the messages. This message generally called through update attribute of any action which we do in front end. Generally we define growl component as like below.

<p:growl id="growl" showDetail="true" sticky="true"
   showSummary="false" autoUpdate="true" widgetVar="growlWV"/>

In below example we are displaying messages on click of the command button. We defined update attribute which is referenced to the growl message component.

<p:commandButton value="Save" actionListener="#{myBean.getMyMessage}" update="growl" /> 
In server side we need to set the messages in the context.

public void saveMessage() {
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful",  "Your message: " + message) );

But in some cases we may need to trigger the same growl component from java script. This is the case when we do ajax events. We can use below approach to call the growl component in java script.

function renderMessage() { 


Post a Comment

Powered by Blogger.