webtier@glassfish.java.net

Re: Bean Validation, JSF and stuff

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Tue, 08 Mar 2011 09:48:12 -0600

If I'm understanding things correctly, this RichFaces feature might be
helpful here: http://in.relation.to/18381.lace

On 3/8/11 9:13 AM, Joel Weight wrote:
> I'm assuming you mean JSR-303 when you say Bean Validation. If that's
> the case, and if I understand your problem correctly, the issue is
> that JSF only executes field level validators. It does not perform
> any bean level validation. Your @Size constraint is a field level
> validator because it is only validating a single field. Your person
> validator is a bean (or class) level validator because it validates
> the instance, not the field. I went through the same struggle to
> figure that out. If you want more information than I've given here,
> have a look at the blog post I wrote when I finally figured it out.
> http://digitaljoel.nerd-herders.com/2010/04/12/jsf-2-jsr-303-and-you/
>
> Hope that helps.
> Joel
>
> On Tue, Mar 8, 2011 at 6:07 AM, Thibaud Vibes <tvibes_at_onyme.com
> <mailto:tvibes_at_onyme.com>> wrote:
>
> 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
>
>


-- 
Jason Lee
Senior Member of Technical Staff
GlassFish REST API / Administration Console
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com