akaliza
akaliza

Reputation: 3911

Show message only when there are no messages for other components

I have 3 messages displayed when validating the form, kind of this :

<p:message id="msgCity1"  for="city1" styleClass="required" display="text" />
<p:message id="msgCity2"  for="city2" styleClass="required" display="text" />
<p:message id="msgCountry"  for="msgCountry" styleClass="required" display="text" />

the first(msgCity1) and second(msgCity2) messages are validated on event (keyup) the last one is validate on server side, I would like to show the last message (msgCountry), if the validation is ok for the first 2 messages, I mean if the message are empty,

For that I would like to use rendered on the last message but I do not how I can get the value of the first 2 message in xhtml

Upvotes: 3

Views: 101

Answers (1)

BalusC
BalusC

Reputation: 1108567

Rather hook on UIInput#isValid() directly than on the presence of a message for the input.

E.g.

<h:inputText id="city1" binding="#{city1}" ... />
<h:inputText id="city2" binding="#{city2}" ... />
...
<p:message for="msgCountry" ... rendered="#{city1.valid and city2.valid}" />

Upvotes: 1

Related Questions