views:

874

answers:

2

Hi !

I am trying to validate a rich:calendar for not null input using <rich:beanValidator />, but i am not able to validate for null inputs.

For example in my constraits.xml file, i validate getter for calendar:

<getter name="dateOfBirth">

  <constraint annotation="javax.validation.constraints.Past"/> (works fine)

  <constraint annotation="javax.validation.constraints.NotNull" /> (not work)

  <constraint annotation="org.hibernate.validator.constraints.NotEmpty"/> (not work)

</getter>

Those last two constraint did not worked because "DateTime" data type dose not recognize them ? (first of them as far as i know is used for numeric values and second one for strings).

There is such a constraint for date time data type ? Could i validate somehow using constraints written in xml file for not null inputs ?

I am forced to used required="true" in xhtml for this kind of validation (not null) for rich:calendar (if i am using hibernate validator) ?

Please if you have an idea help me...

Regards, Mircea

A: 

@NotNull: The annotated element must not be null. Accepts any type.

Did you check whether it is really null? Because it might have been set to new Date() for example. Also, try if works with annotations, rather than constraints.xml (it could be a bug in beanvalidator)

Anyway, required="true" seems a good solution.

Bozho
Hi Bozho, Thanks a lot for posting ! I tryed using annotations written in java classes but also, the not null validation is not working. I have the same feeling that when rich:calendar is enabled it is initialized by default with new Date(), and this fact "tricks" not null validator ,in GUI. May be a custom validator for new Date() ( which as far as i know will be current date, but is not set on GUI for calendar , so i guess that will fail) could be another solution.Regards
Radu
well, try checking (with debugger, ot System.out) the value of the calendar - whether it is really null, or a new Date
Bozho
as i tested , the value is null in getters an d setters, i was surprised about that because i was expected to get a non null value...
Radu
A: 

JSF does not validate null fields. JSF 2 however has the option to validate null's in order to be compliant with the bean validation framework.

MCA