This :
<h:outputLabel for="birthdate">Birthdate (yyyy-MM-dd)</h:outputLabel>
<h:inputText id="birthdate" value="#{userController.user.birthdate}">
<f:convertDateTime pattern="yyyy-MM-dd" />
<f:ajax event="blur" render="birthdateMessage" />
</h:inputText>
<h:message id="birthdateMessage" for="birthdate" />
works like a charm in the form. But I can't seem to find a way to move this validation at the entity:
@Temporal(TemporalType.DATE) // pattern ?
@Past
private Date birthdate;
If I remove the <f:convertDateTime pattern="yyyy-MM-dd" />
the form won't validate correctly. So should I keep this in the form - or is there a way to pass the validation in the entity (as I've done with the rest of the fields like email etc)
Bonus: is this the correct way of passing a Date to the persistent layer ? Does it take care of timezones etc ? I always use Joda in SE and IIRC Date is one of the most problematic Java classes. But when I reverse engineered the entities from the tables (using the Eclipse JPA project option Create Entities from tables) that's what I got (in the (MySQL) table the birthdate attribute is of type DATE).
EDIT: I find it better style to have the all validations at the entity than at the view or at the controller - any objections welcome