0

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

vinay
  • 950
  • 1
  • 11
  • 27
  • 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 Sep 16 '14 at 21:52
  • Your question is confusing. I'm not seeing `` anywhere in this code snippet (only a ``). The second message you describe indeed clearly comes from ``, but this is also nowhere visible in this code snippet. Please post a true MCVE: http://stackoverflow.com/help/mcve – BalusC Sep 17 '14 at 05:31
  • @BalusC Thank you for looking into this. I dont really have a and in my code. I am only using . But I would like to mention that my application has a master template which has 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 Sep 17 '14 at 14:02
  • 1
    Why do you think that the code of the template isn't being used? What's the purpose of the template then? – BalusC Sep 17 '14 at 14:07
  • @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 Sep 17 '14 at 14:09
  • Probably page refresh(ajax=false) invokes the growl from main template? – vinay Sep 17 '14 at 14:13
  • If I get rid of growl and its references in main template, the problem is fixed. I am happy about that but I am curious why is the growl in main template called? Can we stop it from being used? – vinay Sep 17 '14 at 15:43
  • @BalusC This question help me understand growl better http://stackoverflow.com/questions/15598192/how-to-use-pgrowl-only-for-confirmation-not-validation-jsf2-primefaces . Thank you for your answers. – vinay Sep 17 '14 at 18:58

2 Answers2

3

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

mins
  • 6,478
  • 12
  • 56
  • 75
Alagan
  • 31
  • 2
1

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.

vinay
  • 950
  • 1
  • 11
  • 27
Pankaj VishwasRao
  • 153
  • 1
  • 1
  • 11
  • Thank you Pankaj. I tried your suggestion but I had no luck. Can you check the comments above to get an update – vinay Sep 17 '14 at 14:11