PrimeFaces Calendar mindate / maxdate format error

calendarjsfjsf-2primefaces

I'm trying to set mindate and maxdate in a Primefaces Calendar control. I get an error java.lang.IllegalArgumentException: Cannot format given Object as a Date

The code is very simple:

<p:calendar value="" pattern="MM/dd/yyyy" mindate="01/01/2012" maxdate="05/31/2012" mode="inline"/>

I assume the problem is the format used in the strings for the mindate and maxdate attributes, but I can't see what the problem would be, especially as I've explicitly defined the format in the pattern attribute.

Best Answer

Nothing wrong with the format or the mindate/maxdate.

The problem is actually the value="". I presume you're trying to display blank as the default. The <p:calendar/> component being a strictly-typed component will attempt to parse and convert " " to a java.util.Date object. Obviously that's going to cause it to choke.

You're better off binding the value attribute to an uninitialized Date field in your backing bean or setting a default value with the pageDate attribute, which is not as strongly-typed (takes an Object)