I am using Omnifaces <o:validateBean />
to use JSR303 bean validation with a class level constraint. My question is based on a former question about how to attach message to specific components. Since Omnifaces 2.6 there is a showMessageFor
attribute which solves my question at that time completely (so big thanks to the developers of Omnifaces library ;-). My problem is that I can not get it to work.
Here is my setting. I have three input fields, two of them are coupled in a class level constraint (weddingDay must be smaller than silverWeddingAnniversary; I could attach more code if necessary).
@DayIsBeforeAnniversary
@Entity
public class Person implements Serializable
{
private String name;
@Temporal(TemporalType.DATE)
private Date weddingDay;
@Temporal(TemporalType.DATE)
private Date silverWeddingAnniversary;
...
}
<h:form id="main_form">
<p:messages />
<p:outputLabel value="Name" for="id_name" />
<p:message for="id_name" />
<p:inputText id="id_name" value="#{personController.person.name}" /><br />
<p:outputLabel value="Wedding Day" for="id_wedding" />
<p:message for="id_wedding" />
<p:calendar id="id_wedding" value="#{personController.person.weddingDay}" /><br />
<p:outputLabel value="Silver Wedding Anniversary" for="id_anniversary" />
<p:message for="id_anniversary" />
<p:calendar id="id_anniversary" value="#{personController.person.silverWeddingAnniversary}" /><br/>
<p:commandButton
value="test"
action="#{personController.navigate()}"
update="@all"/>
<o:validateBean
value="#{personController.person}"
showMessageFor="id_wedding id_anniversary" />
</h:form>
So my intention is to show the validation message in the <p:message/>
tags corresponding to the two <p:calendar/>
tags of which I specified the ID (showMessageFor="id_wedding id_anniversary"
).
The actual outcome is a bit different. Two messages show up in the general <p:messages/>
tag. And all input fields are red highlighted (even the input for the name; every input and label has class="ui-state-error"). Actually there is not much difference when I leave out the showMessageFor attribute completely (except there is only one message rendered in the <p:messages/>
).
So what am I doing wrong respectivly how can I tell the error messages to appear in the two specific <p:message/>
tags and how can I prevent the input field for the uninvolved name to become red?
(using Omnifaces 2.6.8 on Glassfish 4.1.1)