How can we use multiple <h: messages> tags or <h: message> tags on the same JSF page?
My problem is that I have two forms on the same JSF page, each of which has its own <h:message> or <h:messages> . Since we know that message / message tags print any validation errors, so what happens is, suppose I leave the fields of either of the two forms blank, they should print "Fields cannot be empty" or some kind of message. He gives this message, but he gives two times, because there are two forms. Therefore, I see the same error / validation message in each of the two forms.
So, I need the <h:messages> or <h:message> display an error / validation message only once for each of their respective forms!
So any help would be greatly appreciated!
If you are using JSF 2, you can just submit and update the ajax form. This allows you to partially update the view.
<h:form> <h:messages /> ... <h:commandButton ...> <f:ajax execute="@form" render="@form" /> </h:commandButton> </h:form> <h:form> <h:messages /> ... <h:commandButton ...> <f:ajax execute="@form" render="@form" /> </h:commandButton> </h:form> Or if you can't / don't want to use ajax for some non-obvious reason, or are still using legacy JSF 1.x, then check the rendered <h:messages> attribute if the desired form is submitted or not.
<h:form binding="#{form1}"> <h:messages rendered="#{form1.submitted}" /> ... <h:commandButton ... /> </h:form> <h:form binding="#{form2}"> <h:messages rendered="#{form2.submitted}" /> ... <h:commandButton ... /> </h:form> <h:message> should not have this problem, by the way, contrary to what you mean in your question.