I had similar problems with the calendar.
For one, it accepts dates with two digits, although pattern="dd.MM.yyyy" . For example, 20.06.12 will be displayed in the calendar pop-up window as 20.06.2012 , misleading the user to assume that the date was correctly recognized. But the 12th year is really set.
Anyway, I ended up installing <f:validator> inside <p:calendar> as follows:
<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 do some validation on a 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 that this prevents dates below 1000, but in my case it is absolutely clear that the date cannot be lower than 2000.
So this suggestion: use Validator to make sure the dates are correct. I know that this is not an ideal solution, but a possible workaround.
Otherwise, try asking about it on the surfaces forum.
source share