spring-framework / org.springframework.beans.propertyeditors / CustomDateEditor / <init>

<init>

CustomDateEditor(dateFormat: DateFormat, allowEmpty: Boolean)

Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.

The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Otherwise, an IllegalArgumentException gets thrown in that case.

Parameters

dateFormat - DateFormat to use for parsing and rendering

allowEmpty - if empty strings should be allowed

CustomDateEditor(dateFormat: DateFormat, allowEmpty: Boolean, exactDateLength: Int)

Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering.

The "allowEmpty" parameter states if an empty String should be allowed for parsing, i.e. get interpreted as null value. Otherwise, an IllegalArgumentException gets thrown in that case.

The "exactDateLength" parameter states that IllegalArgumentException gets thrown if the String does not exactly match the length specified. This is useful because SimpleDateFormat does not enforce strict parsing of the year part, not even with setLenient(false). Without an "exactDateLength" specified, the "01/01/05" would get parsed to "01/01/0005". However, even with an "exactDateLength" specified, prepended zeros in the day or month part may still allow for a shorter year part, so consider this as just one more assertion that gets you closer to the intended date format.

Parameters

dateFormat - DateFormat to use for parsing and rendering

allowEmpty - if empty strings should be allowed

exactDateLength - the exact expected length of the date String