public class CustomDateMidnightEditor extends PropertyEditorSupport
org.joda.time.DateMidnight, supporting
a custom org.joda.time.format.DateTimeFormatter. This class
is modeled on Spring's CustomDateEditor.
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 calls in a custom
initBinder method.
DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor),
org.springframework.web.servlet.mvc.BaseCommandController#initBinder| Constructor and Description |
|---|
CustomDateMidnightEditor(org.joda.time.format.DateTimeFormatter dateFormat,
boolean allowEmpty)
Create a new CustomDateEditor instance, using the given DateFormat for
parsing and rendering.
|
CustomDateMidnightEditor(org.joda.time.format.DateTimeFormatter dateFormat,
boolean allowEmpty,
int exactDateLength)
Create a new CustomDateEditor instance, using the given DateFormat for
parsing and rendering.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getAsText()
Format the Date as String, using the specified DateFormat.
|
void |
setAsText(String text)
Parse the Date from the given text, using the specified DateFormat.
|
addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, setValue, supportsCustomEditorpublic CustomDateMidnightEditor(org.joda.time.format.DateTimeFormatter dateFormat,
boolean allowEmpty)
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.
dateFormat - DateFormat to use for parsing and renderingallowEmpty - if empty strings should be allowedpublic CustomDateMidnightEditor(org.joda.time.format.DateTimeFormatter dateFormat,
boolean allowEmpty,
int exactDateLength)
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".
dateFormat - DateFormat to use for parsing and renderingallowEmpty - if empty strings should be allowedexactDateLength - the exact expected length of the date Stringpublic void setAsText(String text) throws IllegalArgumentException
setAsText in interface PropertyEditorsetAsText in class PropertyEditorSupportIllegalArgumentExceptionpublic String getAsText()
getAsText in interface PropertyEditorgetAsText in class PropertyEditorSupportCopyright © 2016 Jasig. All Rights Reserved.