Growl is not show me after delete

494 Views Asked by At

My purpose is to show an alert after a delete : So my .xhmtl code is:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html">
        <h:form id="form">
    ....
        <p:growl autoUpdate="true" id="message" for="message" showDetail="true"/>
        </h:form>

and in my bean after delete I do:

         FacesMessage infoMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, "DELETE", "DELETE OK" );
         FacesContext.getCurrentInstance().addMessage("form:message", infoMsg);

The problem is the object is deleted correctly but the alert is not show. Anyone can help me?

2

There are 2 best solutions below

7
tsotzolas On

In Primefaces 7 Documentation growl does not have autoupdate.

So you are using a different version.

I give you some sample code in case that you want to delete an item in a datatable

<h:form id="form">
            <p:growl id="msgs1" showDetail="true" life="3000"/>

          .....                       

                   <p:dataTable  value="#{ManageBean.dataList}" 
                             var="record" 
                             widgetVar="rolesTable" 
                             rowKey="#{record}">
                    <p:column headerText="Data" sortBy="#{record.desc }"
                        <h:outputText value="#{record.desc}"/>
                    </p:column>


                    <p:column headerText="Actions" width="100">
                        <p:commandLink

                                update="form" action="#{ManageBean.delete(record)}"
                                >
                            <h:graphicImage name="/icons/delete.png"
                                            title="Delete"/>
                        </p:commandLink>

                </p:dataTable>

And the code in ManageBean

 public void delete(ObjectType object) {

    //Your code for delete
    db.dbTransactions.deleteObject(object);

        //Create the message
        FacesMessage msg = new FacesMessage("Successful Delete");
        FacesContext.getCurrentInstance().addMessage(null, msg);

        //Remove the object from your list
        dataList.remove(object);
    }
}
4
AudioBubble On

Place growl component in own form like this.

     <h:form id="growlForm">
        <p:growl showDetail="true" life="8000" keepAlive="true"/>
    </h:form>

And create a message like this

    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Success!", "Deleted"));
    PrimeFaces.current().ajax().update("growlForm");

Instead of using

PrimeFaces.current().ajax().update("growlForm");

You can also update the form by referencing it from the update attribute in your p:commandButton component. Also, your Bean which handels the request should not be RequestScoped, but ViewScoped.