Schedule "Privlines" allows an incorrect date

I use the integer calendar, but I am allowed to enter an invalid date. enter the date as 06/06/2012 in the input field for the date field and save the entry. It saves the date, storing the date from 07/07/2012. The same behavior can be observed in the window as well.

Link: http://www.primefaces.org/showcase/ui/calendarBasic.jsf

Here is my code

<p:calendar id="copyStartDateCalendar" pattern="dd/MM/yyyy" mode="popup" showOn="button" size='8' > <f:convertDateTime pattern="MM/yyyy" /> </p:calendar> 

What needs to be done, since there seems to be some error with the component itself.

Thanks and Regards

Tarun Madaan

+4
source share
3 answers

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.

+2
source

Try using readonly="true" in which case you do not need to use server-side validators. This option allows the end user to only select a date from the calendar pane.

+2
source

Does your template and f: convertDateTime have different templates?

Probably, he will not be able to determine what you want in the converter as input, like dd / mm / yyyy - then your converter tries to convert it to MM / yyyy.

The problem you are describing is that the reduction is set to true in the simplest date formatting in side primitives (this is the default action). To make you use, you use your convertDatetime, which should fix it, but your templates may not match it.

However, if you use the PF check <4, you will get a java script problem, since there is an error in the p: calendar converters that return zero objects after the check - you can make some manual corrections for this inside the PF code after it is restored.

0
source

All Articles