users@glassfish.java.net

Re: Bean Validation, JSF and stuff

From: Alexis Moussine-Pouchkine <alexis.moussine-pouchkine_at_oracle.com>
Date: Tue, 8 Mar 2011 13:13:52 +0100

(adding webtier alias)

On 8 mars 2011, at 13:11, Markus Eisele wrote:

> Hi,
>
> I was wondering if somebody has an idea what's exactly going wrong here.
> I'm playing around with Bean Validation and JSF 2.0 these days and I have a
> very basic domain object (Person) with name and surname. Both attributes with
> bean validation contraints ( @Size(min = 3, message = "Please provide a surname > 3 char")).
> Works fine, bound to a simple <h:form> via a PersonController (complete example attached).
> But I found a few things, I would like to have some comments on:
>
> 1) I implemented a simple ValidPerson constraint which simply always returns false in it's isValid method.
> If I attach this constraint to my PersonController.person it's simply never called.
> Am I missing any kind of configuration?
>
> 2) Trying to resolve this, I found a post about the need to set a JSF context-param
> <context-param>
> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
> <param-value>true</param-value>
> </context-param>
> Enabling this in the web.xml seems to cause the @Size constraints being no longer evaluated. I had to add an additional
> @NotNull constraint to check it. It's clear to me, that the @Size can't check for the "real Size" of an Object but it should
> make the assumption, that if null is given as the object it will never have a Size of anything :)
>
> Thanks for comments and ideas,
> Markus
>
>