2

Here is the example code from PrimeFaces showcase about <p:growl> tag.In this example,when you click "Save" button,appears two messages are "Succesful" and "SecondMessage".

This link is what I'm talking about.

This is example code from PrimeFaces Showcase

<h:form> 
    <p:growl id="growl" showDetail="true" sticky="true" />  

    <p:panel header="Growl">  
        <h:panelGrid columns="2" cellpadding="5">  
            <p:outputLabel for="msg" value="Message:" />   
            <p:inputText id="msg" 
                         value="#{growlView.message}" 
                         required="true" />  
        </h:panelGrid>  

        <p:commandButton value="Save" 
                         actionListener="#{growlView.saveMessage}" 
                         update="growl" />  
    </p:panel> 
</h:form>

And a bean GrowlView.java from PrimeFaces Showcase again.

@ManagedBean
public class GrowlView {

    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void saveMessage() {
        FacesContext context = FacesContext.getCurrentInstance();

        context.addMessage(null, new FacesMessage("Successful",  "Your message: " + message) );
        context.addMessage(null, new FacesMessage("Second Message", "Additional Message Detail"));
    }
}

My question is, how can I make "Succesful" messages's sticky=true, SecondMessage's sticky=false?

I try to make this with two <p:growl> tags with change second growl's position and sticky.But if you close the first growl,second growl's position not change like the PrimeFaces Showcase example.

wittakarn
  • 3,124
  • 1
  • 18
  • 31
n.Sabri
  • 21
  • 1
  • 2
  • In the provided example the messages are handled by the same growl. Check what happens when each growl has two messages. – Seitaridis Sep 29 '14 at 12:20
  • When I try to make this with 2 growls first growl on top of the second growl.I can solve this with positioning any growl.But if you close the upper growl ,following growl's position does not change because of my positioning.My goal is that when you close upper growl,following growl goes the closed growl's position, like the PrimeFaces showcase example. – n.Sabri Sep 29 '14 at 13:18

1 Answers1

1

This is the modified example code:

<h:form id="growlForm">
    <p:growl id="growl1" showDetail="true" sticky="true" />
    <p:growl id="growl2" showDetail="true" sticky="false" />

    <p:panel header="Growl">
        <h:panelGrid columns="2" cellpadding="5">
            <p:outputLabel for="msg" value="Message:" />
            <p:inputText id="msg" value="#{growlView.message}"
                required="true" />
        </h:panelGrid>

        <p:commandButton value="Save"
            actionListener="#{growlView.saveMessage}" update="growl1 growl2" />
    </p:panel>
</h:form>

And the saveMethod:

public void saveMessage() {
    FacesContext context = FacesContext.getCurrentInstance();

    context.addMessage("growlForm:growl1", new FacesMessage("Successful",  "Your message: " + message) );
    context.addMessage("growlForm:growl1", new FacesMessage("Second Message", "Additional Message Detail"));

    context.addMessage("growlForm:growl2", new FacesMessage("Successful 2",  "Your message: " + message) );
    context.addMessage("growlForm:growl2", new FacesMessage("Second Message 2", "Additional Message Detail"));
}

I found something odd in this case. At the beginning both growls have the four messages added in the saveMethod. After a while(6 seconds, default value for life attribute), all the messages for from growl1 dissapear as expected.

I don't know why both growls end up with 4 messages each. I have searched for existing growl issues and saw an issue related to multiple grows.

Take a look at the generated html. Do you have the same thing?

Seitaridis
  • 4,459
  • 9
  • 53
  • 85
  • Yes, I have exactly the same thing! – n.Sabri Sep 29 '14 at 14:21
  • The reported issue was discussed on PrimeFaces forum(http://forum.primefaces.org/viewtopic.php?f=3&t=17808). The issue is not fixed yet. I suggest you to report the duplicate messages for both growls. – Seitaridis Sep 29 '14 at 14:50