JSF ValidationError with Custom Converters

posted by Jake on

Here's an important tidbit... JSF does not give any default validators for your data if you use a custom converter. If you're getting a ValidationError exception, overriding equals and hashcode methods might be a good idea. For more, read on...

Here was my code:

<h:selectmanycheckbox id="recipients-grp" value="#{email.sendToRecipients}" converter="#{entityConverter}" layout="pageDirection">
<f:selectitems id="recip" value="#{r:convertSelectItemList(emailBean.allRecipients)}">
</f:selectitems></h:selectmanycheckbox>

I was seeing a lot of this:

assignmentCreateForm:j_id47:0:recipients-grp: Validation Error: Value is not valid

It turns out that when you're using a custom converter, which I am (entityConverter), there are no default validators provided by JSF.

This means that you are required to prove to JSF that the objects that you're retrieving from the f:selectItems collection will fit into the h:selectManyCheckbox value you have specified. In order to help JSF determine the compatibility, you must provide a meaningful hashcode and equals method for your f:selectItems object.

Leave a comment

blog comments powered by Disqus