users@glassfish.java.net

Re: Bean Validation, JSF and stuff

From: Thibaud Vibes <tvibes_at_onyme.com>
Date: Tue, 08 Mar 2011 14:13:03 +0100

(forget to answer in the original mailing-list)

-------- Message original --------
Sujet: Re: Bean Validation, JSF and stuff
Date : Tue, 08 Mar 2011 14:07:56 +0100
De : Thibaud Vibes <tvibes_at_onyme.com>
Répondre à : webtier_at_glassfish.java.net
Pour : webtier_at_glassfish.java.net



Hello,

i may bring some lights....

Le 08.03.2011 13:13, Alexis Moussine-Pouchkine a écrit :
> (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?
Unfortunately, this message was forwarded on the webtier mailing-list
but i don't get your "complete example attached" and cannot reproduce...

>> 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 :)
The Bean validation specs indicates for @Size Built-in constraint:
/ "null" elements are considered valid/

(see spec 1.0-final, p107, example 6.9)

So it seems to be "the normal behavior" regarding to the specification
if you force empty strings to be "submitted" as null objects.
>> Thanks for comments and ideas,
>> Markus
>>
>>
Hope this helps
Thibaud