com.vaadin.ui.
Class DateField
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractField
com.vaadin.ui.DateField
All Implemented Interfaces:
Buffered, BufferedValidatable, Property, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.ShortcutNotifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, Field, Serializable, EventListener
Direct Known Subclasses:
- extends AbstractField
- implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier
public class DateField
A date editor component that can be bound to any Property
that is
compatible with java.util.Date
.
Since DateField
extends AbstractField
it implements
the Buffered
interface.
A DateField
is in write-through mode by default, so
AbstractField.setWriteThrough(boolean)
must be called to
enable buffering.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
static class |
DateField.UnparsableDateString
|
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField |
---|
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent |
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent |
---|
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.Field |
---|
Field.ValueChangeEvent |
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered |
---|
Buffered.SourceException |
Nested classes/interfaces inherited from interface com.vaadin.data.Property |
---|
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer |
Field Summary | |
---|---|
static int |
RESOLUTION_DAY
Resolution identifier: days. |
static int |
RESOLUTION_HOUR
Resolution identifier: hours. |
static int |
RESOLUTION_MIN
Resolution identifier: minutes. |
static int |
RESOLUTION_MONTH
Resolution identifier: months. |
static int |
RESOLUTION_MSEC
Resolution identifier: milliseconds. |
static int |
RESOLUTION_SEC
Resolution identifier: seconds. |
static int |
RESOLUTION_YEAR
Resolution identifier: years. |
Constructor Summary | |
---|---|
DateField()
Constructs an empty DateField with no caption. |
|
DateField(Property dataSource)
Constructs a new DateField that's bound to the specified
Property and has no caption. |
|
DateField(String caption)
Constructs an empty DateField with caption. |
|
DateField(String caption,
Date value)
Constructs a new DateField with the given caption and
initial text contents. |
|
DateField(String caption,
Property dataSource)
Constructs a new DateField that's bound to the specified
Property and has the given caption String . |
Method Summary | |
---|---|
void |
addListener(FieldEvents.BlurListener listener)
Adds a BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
void |
addListener(FieldEvents.FocusListener listener)
Adds a FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are changed. |
String |
getDateFormat()
Returns a format string used to format date value on client side or null if default formatting from Component.getLocale() is used. |
String |
getParseErrorMessage()
Return the error message that is shown if the user inputted value can't be parsed into a Date object. |
int |
getResolution()
Gets the resolution. |
TimeZone |
getTimeZone()
Gets the time zone used by this field. |
Class<?> |
getType()
Returns the type of the Property. |
protected Date |
handleUnparsableDateString(String dateString)
This method is called to handle a non-empty date string from the client if the client could not parse it as a Date. |
boolean |
isLenient()
Returns whether date/time interpretation is to be lenient. |
boolean |
isShowISOWeekNumbers()
Checks whether ISO 8601 week numbers are shown in the date selector. |
boolean |
isValid()
Tests the current value against registered validators if the field is not empty. |
void |
paintContent(PaintTarget target)
Paints any needed component-specific things to the given UIDL stream. |
void |
removeListener(FieldEvents.BlurListener listener)
Removes a BlurListener from the Component. |
void |
removeListener(FieldEvents.FocusListener listener)
Removes a FocusListener from the Component. |
void |
setDateFormat(String dateFormat)
Sets formatting used by some component implementations. |
protected void |
setInternalValue(Object newValue)
Sets the internal field value. |
void |
setLenient(boolean lenient)
Specifies whether or not date/time interpretation in component is to be lenient. |
void |
setParseErrorMessage(String parsingErrorMessage)
Sets the default error message used if the DateField cannot parse the text input by user to a Date field. |
void |
setPropertyDataSource(Property newDataSource)
Sets the DateField datasource. |
void |
setResolution(int resolution)
Sets the resolution of the DateField. |
void |
setShowISOWeekNumbers(boolean showWeekNumbers)
Sets the visibility of ISO 8601 week numbers in the date selector. |
void |
setTimeZone(TimeZone timeZone)
Sets the time zone used by this date field. |
protected void |
setValue(Object newValue,
boolean repaintIsNotNeeded)
Sets the value of the field. |
protected boolean |
shouldHideErrors()
Returns true if the error indicator be hidden when painting the component even when there are errors. |
void |
validate()
Checks the validity of the Validatable by validating the field with all attached validators except when the field is empty. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.vaadin.ui.Field |
---|
getDescription, setCaption, setDescription |
Field Detail |
---|
RESOLUTION_MSEC
public static final int RESOLUTION_MSEC
- See Also:
- Constant Field Values
Resolution identifier: milliseconds.
RESOLUTION_SEC
public static final int RESOLUTION_SEC
- See Also:
- Constant Field Values
Resolution identifier: seconds.
RESOLUTION_MIN
public static final int RESOLUTION_MIN
- See Also:
- Constant Field Values
Resolution identifier: minutes.
RESOLUTION_HOUR
public static final int RESOLUTION_HOUR
- See Also:
- Constant Field Values
Resolution identifier: hours.
RESOLUTION_DAY
public static final int RESOLUTION_DAY
- See Also:
- Constant Field Values
Resolution identifier: days.
RESOLUTION_MONTH
public static final int RESOLUTION_MONTH
- See Also:
- Constant Field Values
Resolution identifier: months.
RESOLUTION_YEAR
public static final int RESOLUTION_YEAR
- See Also:
- Constant Field Values
Resolution identifier: years.
Constructor Detail |
---|
DateField
public DateField()
Constructs an empty DateField
with no caption.
DateField
public DateField(String caption)
- Parameters:
caption
- the caption of the datefield.
Constructs an empty DateField
with caption.
DateField
public DateField(String caption,
Property dataSource)
- Parameters:
caption
- the captionString
for the editor.dataSource
- the Property to be edited with this editor.
Constructs a new DateField
that's bound to the specified
Property
and has the given caption String
.
DateField
public DateField(Property dataSource)
throws IllegalArgumentException
- Parameters:
dataSource
- the Property to be edited with this editor.- Throws:
IllegalArgumentException
Constructs a new DateField
that's bound to the specified
Property
and has no caption.
DateField
public DateField(String caption,
Date value)
- Parameters:
caption
- the captionString
for the editor.value
- the Date value.
Constructs a new DateField
with the given caption and
initial text contents. The editor constructed this way will not be bound
to a Property unless
Property.Viewer.setPropertyDataSource(Property)
is called to bind it.
Method Detail |
---|
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractField
- Parameters:
target
- the target UIDL stream where the component should paint itself to- Throws:
PaintException
- if the paint operation failed.
Description copied from class: AbstractComponent
Paints any needed component-specific things to the given UIDL stream. The
more general AbstractComponent.paint(PaintTarget)
method handles all general
attributes common to all components, and it calls this method to paint
any component-specific attributes to the UIDL stream.
shouldHideErrors
protected boolean shouldHideErrors()
- Overrides:
shouldHideErrors
in classAbstractField
- Returns:
- true to hide the error indicator, false to use the normal logic to show it when there are errors
Description copied from class: AbstractField
Returns true if the error indicator be hidden when painting the component even when there are errors. This is a mostly internal method, but can be overridden in subclasses e.g. if the error indicator should also be shown for empty fields in some cases.
changeVariables
public void changeVariables(Object source,
Map<String,Object> variables)
- Specified by:
changeVariables
in interfaceVariableOwner
- Overrides:
changeVariables
in classAbstractField
- Parameters:
source
- the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.
Description copied from interface: VariableOwner
Called when one or more variables handled by the implementing class are changed.
handleUnparsableDateString
protected Date handleUnparsableDateString(String dateString)
throws Property.ConversionException
- Parameters:
dateString
-- Returns:
- parsed Date
- Throws:
Property.ConversionException
- to keep the old value and indicate an error
This method is called to handle a non-empty date string from the client if the client could not parse it as a Date. By default, a Property.ConversionException is thrown, and the current value is not modified. This can be overridden to handle conversions, to return null (equivalent to empty input), to throw an exception or to fire an event.
getType
public Class<?> getType()
- Specified by:
getType
in interfaceProperty
- Specified by:
getType
in classAbstractField
- Returns:
- type of the Property
Description copied from interface: Property
Returns the type of the Property. The methods getValue
and
setValue
must be compatible with this type: one must be able
to safely cast the value returned from getValue
to the given
type and pass any variable assignable to this type as an argument to
setValue
.
setValue
protected void setValue(Object newValue,
boolean repaintIsNotNeeded)
throws Property.ReadOnlyException,
Property.ConversionException
- Overrides:
setValue
in classAbstractField
- Parameters:
newValue
- the New value of the field.repaintIsNotNeeded
- True iff caller is sure that repaint is not needed.- Throws:
Property.ReadOnlyException
Property.ConversionException
Description copied from class: AbstractField
Sets the value of the field.
setPropertyDataSource
public void setPropertyDataSource(Property newDataSource)
- Specified by:
setPropertyDataSource
in interfaceProperty.Viewer
- Overrides:
setPropertyDataSource
in classAbstractField
- Parameters:
newDataSource
- the new data source Property.- See Also:
Property.Viewer.setPropertyDataSource(Property)
Sets the DateField datasource. Datasource type must assignable to Date.
setInternalValue
protected void setInternalValue(Object newValue)
- Overrides:
setInternalValue
in classAbstractField
- Parameters:
newValue
- the new value to be set.
Description copied from class: AbstractField
Sets the internal field value. This is purely used by AbstractField to change the internal Field value. It does not trigger valuechange events. It can be overridden by the inheriting classes to update all dependent variables.
getResolution
public int getResolution()
- Returns:
- int
Gets the resolution.
setResolution
public void setResolution(int resolution)
- Parameters:
resolution
- the resolution to set.
Sets the resolution of the DateField.
setDateFormat
public void setDateFormat(String dateFormat)
- Parameters:
dateFormat
- the dateFormat to set- See Also:
com.vaadin.ui.AbstractComponent#setLocale(Locale))
Sets formatting used by some component implementations. See
SimpleDateFormat
for format details.
By default it is encouraged to used default formatting defined by Locale,
but due some JVM bugs it is sometimes necessary to use this method to
override formatting. See Vaadin issue #2200.
getDateFormat
public String getDateFormat()
- Returns:
- the dateFormat
Returns a format string used to format date value on client side or null
if default formatting from Component.getLocale()
is used.
setLenient
public void setLenient(boolean lenient)
- Parameters:
lenient
- true if the lenient mode is to be turned on; false if it is to be turned off.- See Also:
Calendar.setLenient(boolean)
,isLenient()
Specifies whether or not date/time interpretation in component is to be lenient.
isLenient
public boolean isLenient()
- Returns:
- true if the interpretation mode of this calendar is lenient; false otherwise.
- See Also:
setLenient(boolean)
Returns whether date/time interpretation is to be lenient.
addListener
public void addListener(FieldEvents.FocusListener listener)
- Specified by:
addListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Adds a FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.
removeListener
public void removeListener(FieldEvents.FocusListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener
from the Component.
addListener
public void addListener(FieldEvents.BlurListener listener)
- Specified by:
addListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Adds a BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.
removeListener
public void removeListener(FieldEvents.BlurListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener
from the Component.
isShowISOWeekNumbers
public boolean isShowISOWeekNumbers()
- Returns:
- true if week numbers are shown, false otherwise.
Checks whether ISO 8601 week numbers are shown in the date selector.
setShowISOWeekNumbers
public void setShowISOWeekNumbers(boolean showWeekNumbers)
- Parameters:
showWeekNumbers
- true if week numbers should be shown, false otherwise.
Sets the visibility of ISO 8601 week numbers in the date selector. ISO 8601 defines that a week always starts with a Monday so the week numbers are only shown if this is the case.
isValid
public boolean isValid()
- Specified by:
isValid
in interfaceValidatable
- Overrides:
isValid
in classAbstractField
- Returns:
true
if all registered validators claim that the current value is valid or if the field is empty and not required,false
otherwise.- See Also:
AbstractField.isValid()
Tests the current value against registered validators if the field is not empty. Note that DateField is considered empty (value == null) and invalid if it contains text typed in by the user that couldn't be parsed into a Date value.
validate
public void validate()
throws Validator.InvalidValueException
- Specified by:
validate
in interfaceValidatable
- Overrides:
validate
in classAbstractField
- Throws:
Validator.InvalidValueException
- if the value is not valid- See Also:
Validatable.validate()
Description copied from class: AbstractField
Checks the validity of the Validatable by validating the field with all attached validators except when the field is empty. An empty field is invalid if it is required and valid otherwise. The "required" validation is a built-in validation feature. If the field is required, but empty, validation will throw an EmptyValueException with the error message set with setRequiredError().
getParseErrorMessage
public String getParseErrorMessage()
- Returns:
- the error message that the DateField uses when it can't parse the textual input from user to a Date object
- See Also:
setParseErrorMessage(String)
Return the error message that is shown if the user inputted value can't
be parsed into a Date object. If
handleUnparsableDateString(String)
is overridden and it throws a
custom exception, the message returned by
Throwable.getLocalizedMessage()
will be used instead of the value
returned by this method.
setParseErrorMessage
public void setParseErrorMessage(String parsingErrorMessage)
- Parameters:
parsingErrorMessage
-- See Also:
getParseErrorMessage()
,handleUnparsableDateString(String)
Sets the default error message used if the DateField cannot parse the
text input by user to a Date field. Note that if the
handleUnparsableDateString(String)
method is overridden, the
localized message from its exception is used.
setTimeZone
public void setTimeZone(TimeZone timeZone)
- Parameters:
timeZone
- the time zone to use for time calculations.- See Also:
getTimeZone()
Sets the time zone used by this date field. The time zone is used to
convert the absolute time in a Date object to a logical time displayed in
the selector and to convert the select time back to a Date object.
If no time zone has been set, the current default time zone returned by
TimeZone.getDefault()
is used.
getTimeZone
public TimeZone getTimeZone()
- Returns:
- the current time zone
Gets the time zone used by this field. The time zone is used to convert
the absolute time in a Date object to a logical time displayed in the
selector and to convert the select time back to a Date object.
If null
is returned, the current default time zone returned by
TimeZone.getDefault()
is used.