I had similar problems with the primefaces calendar.
For one it accepts dates with two digits though a pattern of pattern="dd.MM.yyyy"
is set. Like 20.06.12
will be shown in the calendar popup as 20.06.2012
misleading the user to think the date was correctly recognized. But the year 12 is actually set.
Anyways, I ended up setting a <f:validator>
inside the <p:calendar>
like this:
<p:calendar value="#{abschnittDView.bogen.pruefungsDatum}
mode="popup" locale="de" pattern="dd.MM.yyyy" required="true"
requiredMessage="Please provide a date."
converterMessage="Date is invalid.">
<f:convertDateTime type="date" pattern="dd.MM.yyyy"
timeZone="Europe/Berlin" locale="de" />
<f:validator validatorId="de.common.DateValidator" />
</p:calendar>
Then doing some validation on the given date:
@FacesValidator(DateValidator.VALIDATOR_ID)
public class DateValidator implements Validator {
public static final String VALIDATOR_ID = "de.common.DateValidator";
@Override
public void validate(FacesContext facesContext, UIComponent component,
Object value) throws ValidatorException {
Date inputDate = (Date) value;
Calendar cal = Calendar.getInstance();
cal.setTime(inputDate);
if (cal.get(Calendar.YEAR) < 1000) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please provide a date with 4 digits for the year", null));
}
}
I know this prevents dates below 1000 but in my case it is absolutely clear that the date can not be lower then 2000.
So the suggestion is: Use a Validator
to make sure the dates are correct.
I know it is not the perfect solution but maybe a possible workaround.
Otherwise, try to ask for this on the primefaces forum.