java.util.Date,
supporting a custom java.text.DateFormat.
This is not meant to be used as system PropertyEditor but rather as locale-specific date editor within custom controller code, parsing user-entered number strings into Date properties of beans and rendering them in the UI form.
In web MVC code, this editor will typically be registered with
binder.registerCustomEditor.
java.util.Date , java.text.DateFormat , org.springframework.validation.DataBinder#registerCustomEditor
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private final DateFormat | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | CustomDateEditor(DateFormat
the DateFormat to use for parsing and rendering dateFormat, boolean if empty strings should be allowed allowEmpty)Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering. |
| public | CustomDateEditor(DateFormat
the DateFormat to use for parsing and rendering dateFormat, boolean if empty strings should be allowed allowEmpty, int the exact expected length of the date String exactDateLength)Create a new CustomDateEditor instance, using the given DateFormat for parsing and rendering. |
| Modifier and Type | Method and Description |
|---|---|
| public String | getAsText()
Overrides java. Implements java. |
| public void | setAsText(String
The string to be parsed. text)Overrides java. Implements java. |
| allowEmpty | back to summary |
|---|---|
| private final boolean allowEmpty | |
| dateFormat | back to summary |
|---|---|
| private final DateFormat dateFormat | |
| exactDateLength | back to summary |
|---|---|
| private final int exactDateLength | |
| CustomDateEditor | back to summary |
|---|---|
| public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty) 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.
| |
| CustomDateEditor | back to summary |
|---|---|
| public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty, int exactDateLength) 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
| |
| getAsText | back to summary |
|---|---|
| public String getAsText() Overrides java. Implements java. Format the Date as String, using the specified DateFormat.
| |
| setAsText | back to summary |
|---|---|
| public void setAsText(String text) throws IllegalArgumentException Overrides java. Implements java. Parse the Date from the given text, using the specified DateFormat.
| |