0
votes

I have a form with p:messages and with a inputText field. The inputText field is required and has a requiredMessage. When the commandButton is clicked with empty inputText, I want to show messages only using p:messages, but I see the same message twice. Once using p:message and the other I believe is server side validation message(like a growl at top right corner). My relevant code is as follows :

<h:form id="saveUserForm">
  <p:panel style="border:none">
    <p:messages id="messages" closable="true" autoUpdate="true"  />
    <div align="left">
        <p:panelGrid styleClass="userPanel">                            
            <p:row>                                
                <p:column colspan="4">
                    <p:inputText id="street" value="" size="67" maxlength="100" required="true" requiredMessage="Street is required" />
                </p:column>
            </p:row>                            
            <p:row>
                <p:column colspan="4">
                    <div align="center">
                        <p:commandButton action="#{userController.add}" rendered="#{mode eq 'add'}" value="Add" ajax="false" update=":saveUserForm"/>
                        <p:commandButton action="#{userController.update}" rendered="#{mode ne 'add'}" value="Update" ajax="false" update=":saveUserForm"/>
                        <p:commandButton action="#{userController.prepareList}" value="Cancel" immediate="true"/>
                    </div>
                </p:column>
            </p:row>
        </p:panelGrid>
    </div>
  </p:panel>
</h:form>

Not sure why I am seeing the requiredMessage twice. Any ideas?

EDIT : Adding growl code for master template

<p:growl id="messages" showDetail="true" sticky="true" autoUpdate="true"/>

Screenshot of what I see :

enter image description here

2
The p:growl tag is used to display messages in the growl format. If you have included both tags, you'll get the results you are seeing. Are you sure you aren't including that tag somewhere? - codeturner
Your question is confusing. I'm not seeing <p:message> anywhere in this code snippet (only a <p:messages>). The second message you describe indeed clearly comes from <p:growl>, but this is also nowhere visible in this code snippet. Please post a true MCVE: stackoverflow.com/help/mcve - BalusC
@BalusC Thank you for looking into this. I dont really have a <p:message> and <p:growl> in my code. I am only using <p:messages>. But I would like to mention that my application has a master template which has <p:growl> in it. Do you think somehow growl is being called? I am editing the code to show twmplate growl and also added update attribute to commandButton. Not sure if I can add a screenshot here. - vinay
Why do you think that the code of the template isn't being used? What's the purpose of the template then? - BalusC
@BalusC I agree with you, but I am only updating the current form, so I am not expecting the growl from master template to be invoked. I also agree I dont have good 'id' for growl and I have to work on them. Is that the problem? - vinay

2 Answers

3
votes

Remove showDetail="true". Its default value is false.

1
votes

I think, in your case messsage is get added to both p:message and p:growl

Try this, (Primefaces 4.0 and above)

Remove autoUpdate="true" from p:messages and add update=":saveUserForm" in p:commandButton so that only p:message will update. And make sure that p:growl is not updating on button click.

OR Try This

<p:growl globalOnly="true" autoUpdate="false">

by this the messages from server side only are shown in growl.

EDIT : Make sure that the components in templates are not being used.