public class DateField extends AbstractField<Date> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, LegacyComponent
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.
Modifier and Type | Class and Description |
---|---|
static class |
DateField.UnparsableDateString |
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
Field.ValueChangeEvent
Buffered.SourceException
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
Modifier and Type | Field and Description |
---|---|
static Resolution |
RESOLUTION_DAY
Deprecated.
As of 7.0, use
Resolution.DAY |
static Resolution |
RESOLUTION_HOUR
Deprecated.
As of 7.0, use
Resolution.HOUR |
static Resolution |
RESOLUTION_MIN
Deprecated.
As of 7.0, use
Resolution.MINUTE |
static Resolution |
RESOLUTION_MONTH
Deprecated.
As of 7.0, use
Resolution.MONTH |
static Resolution |
RESOLUTION_SEC
Deprecated.
As of 7.0, use
Resolution.SECOND |
static Resolution |
RESOLUTION_YEAR
Deprecated.
As of 7.0, use
Resolution.YEAR |
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
void |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
void |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
void |
addListener(FieldEvents.BlurListener listener)
Deprecated.
As of 7.0, replaced by
#addBlurListener(BlurListener) |
void |
addListener(FieldEvents.FocusListener listener)
Deprecated.
As of 7.0, replaced by
#addFocusListener(FocusListener) |
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are
changed.
|
void |
discard()
Discards all changes since last commit.
|
protected void |
fireValueChange(boolean repaintIsNotNeeded)
Emits the value change event.
|
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 |
getDateOutOfRangeMessage()
Returns current date-out-of-range error message.
|
String |
getParseErrorMessage()
Return the error message that is shown if the user inputted value can't
be parsed into a Date object.
|
Date |
getRangeEnd()
Returns the precise rangeEnd used.
|
Date |
getRangeStart()
Returns the precise rangeStart used.
|
Resolution |
getResolution()
Gets the resolution.
|
protected TextualDateFieldState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected TextualDateFieldState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
TimeZone |
getTimeZone()
Gets the time zone used by this field.
|
Class<Date> |
getType()
Returns the type of the Field.
|
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.
|
void |
paintContent(PaintTarget target)
Paints the Paintable into a UIDL stream.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the component state from the given design.
|
void |
removeBlurListener(FieldEvents.BlurListener listener)
Removes a
BlurListener from the Component. |
void |
removeFocusListener(FieldEvents.FocusListener listener)
Removes a
FocusListener from the Component. |
void |
removeListener(FieldEvents.BlurListener listener)
Deprecated.
As of 7.0, replaced by
#removeBlurListener(BlurListener) |
void |
removeListener(FieldEvents.FocusListener listener)
Deprecated.
As of 7.0, replaced by
#removeFocusListener(FocusListener) |
void |
setDateFormat(String dateFormat)
Sets formatting used by some component implementations.
|
void |
setDateOutOfRangeMessage(String dateOutOfRangeMessage)
Sets the current error message if the range validation fails.
|
protected void |
setInternalValue(Date 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 |
setRangeEnd(Date endDate)
Sets the end range for this component.
|
void |
setRangeStart(Date startDate)
Sets the start range for this component.
|
void |
setResolution(Resolution 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(Date 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()
Validates the current value against registered validators if the field is
not empty.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
addListener, addListener, addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, attach, beforeClientResponse, clear, commit, detach, fireReadOnlyStatusChange, focus, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getCustomAttributes, getErrorMessage, getInternalValue, getModelType, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, getValue, isBuffered, isEmpty, isImmediate, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isRequired, isValid, isValidationVisible, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInvalidAllowed, setInvalidCommitted, setLocale, setPropertyDataSource, setReadOnly, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setValue, toString, validate, valueChange
addContextClickListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
markAsDirty
isEnabled, isImmediate
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
addShortcutListener, removeShortcutListener
@Deprecated public static final Resolution RESOLUTION_SEC
Resolution.SECOND
@Deprecated public static final Resolution RESOLUTION_MIN
Resolution.MINUTE
@Deprecated public static final Resolution RESOLUTION_HOUR
Resolution.HOUR
@Deprecated public static final Resolution RESOLUTION_DAY
Resolution.DAY
@Deprecated public static final Resolution RESOLUTION_MONTH
Resolution.MONTH
@Deprecated public static final Resolution RESOLUTION_YEAR
Resolution.YEAR
public DateField()
DateField
with no caption.public DateField(String caption)
DateField
with caption.caption
- the caption of the datefield.public DateField(String caption, Property dataSource)
DateField
that's bound to the specified
Property
and has the given caption String
.caption
- the caption String
for the editor.dataSource
- the Property to be edited with this editor.public DateField(Property dataSource) throws IllegalArgumentException
DateField
that's bound to the specified
Property
and has no caption.dataSource
- the Property to be edited with this editor.IllegalArgumentException
public DateField(String caption, Date value)
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.caption
- the caption String
for the editor.value
- the Date value.public void paintContent(PaintTarget target) throws PaintException
LegacyComponent
Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.
It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.
paintContent
in interface LegacyComponent
target
- the target UIDL stream where the component should paint itself
to.PaintException
- if the paint operation failed.protected boolean shouldHideErrors()
AbstractField
shouldHideErrors
in class AbstractField<Date>
protected TextualDateFieldState getState()
AbstractComponent
getState
in class AbstractField<Date>
protected TextualDateFieldState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractField<Date>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void setRangeStart(Date startDate)
startDate
is set to null
, any
value before endDate
will be accepted by the rangestartDate
- - the allowed range's start datepublic void setDateOutOfRangeMessage(String dateOutOfRangeMessage)
dateOutOfRangeMessage
- - Localizable message which is shown when value (the date) is
set outside allowed rangepublic void setRangeEnd(Date endDate)
endDate
is set to null
, any value
after startDate
will be accepted by the range.endDate
- - the allowed range's end date (inclusive, based on the
current resolution)public Date getRangeStart()
startDate
- public Date getRangeEnd()
startDate
- public void changeVariables(Object source, Map<String,Object> variables)
VariableOwner
changeVariables
in interface VariableOwner
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.public void discard()
Buffered
discard
in interface Buffered
discard
in class AbstractField<Date>
protected void fireValueChange(boolean repaintIsNotNeeded)
AbstractField
fireValueChange
in class AbstractField<Date>
protected Date handleUnparsableDateString(String dateString) throws Converter.ConversionException
dateString
- Converter.ConversionException
- to keep the old value and indicate an errorpublic Class<Date> getType()
AbstractField
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
.protected void setValue(Date newValue, boolean repaintIsNotNeeded) throws Property.ReadOnlyException
AbstractField
setValue
in class AbstractField<Date>
newValue
- the New value of the field.repaintIsNotNeeded
- True iff caller is sure that repaint is not needed.Property.ReadOnlyException
protected void setInternalValue(Date newValue)
AbstractField
AbstractField.getInternalValue()
if necessary.setInternalValue
in class AbstractField<Date>
newValue
- the new value to be set.public Resolution getResolution()
public void setResolution(Resolution resolution)
Resolution.DAY
since Vaadin 7.0.resolution
- the resolution to set.public void setDateFormat(String dateFormat)
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.dateFormat
- the dateFormat to setAbstractComponent#setLocale(Locale))
public String getDateFormat()
Component.getLocale()
is used.public void setLenient(boolean lenient)
lenient
- true if the lenient mode is to be turned on; false if it is to
be turned off.Calendar#setLenient(boolean)
,
isLenient()
public boolean isLenient()
setLenient(boolean)
public void addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifier
FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.addFocusListener
in interface FieldEvents.FocusNotifier
FieldEvents.FocusListener
@Deprecated public void addListener(FieldEvents.FocusListener listener)
#addFocusListener(FocusListener)
addListener
in interface FieldEvents.FocusNotifier
public void removeFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifier
FocusListener
from the Component.removeFocusListener
in interface FieldEvents.FocusNotifier
FieldEvents.FocusListener
@Deprecated public void removeListener(FieldEvents.FocusListener listener)
#removeFocusListener(FocusListener)
removeListener
in interface FieldEvents.FocusNotifier
public void addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifier
BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.addBlurListener
in interface FieldEvents.BlurNotifier
FieldEvents.BlurListener
@Deprecated public void addListener(FieldEvents.BlurListener listener)
#addBlurListener(BlurListener)
addListener
in interface FieldEvents.BlurNotifier
public void removeBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifier
BlurListener
from the Component.removeBlurListener
in interface FieldEvents.BlurNotifier
FieldEvents.BlurListener
@Deprecated public void removeListener(FieldEvents.BlurListener listener)
#removeBlurListener(BlurListener)
removeListener
in interface FieldEvents.BlurNotifier
public boolean isShowISOWeekNumbers()
public void setShowISOWeekNumbers(boolean showWeekNumbers)
showWeekNumbers
- true if week numbers should be shown, false otherwise.public void validate() throws Validator.InvalidValueException
validate
in interface Validatable
validate
in class AbstractField<Date>
Validator.InvalidValueException
- if the value is not validAbstractField.validate()
public String getParseErrorMessage()
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(String)
public void setParseErrorMessage(String parsingErrorMessage)
handleUnparsableDateString(String)
method is overridden, the
localized message from its exception is used.parsingErrorMessage
- getParseErrorMessage()
,
handleUnparsableDateString(String)
public void setTimeZone(TimeZone timeZone)
TimeZone.getDefault()
is used.timeZone
- the time zone to use for time calculations.getTimeZone()
public TimeZone getTimeZone()
null
is returned, the current default time zone returned by
TimeZone.getDefault()
is used.public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
readDesign
in interface Component
readDesign
in class AbstractField<Date>
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designpublic void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
writeDesign
in interface Component
writeDesign
in class AbstractField<Date>
design
- The element to write the component state to. Any previous
attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the designpublic String getDateOutOfRangeMessage()
setDateOutOfRangeMessage(String)
Copyright © 2019 Vaadin Ltd. All rights reserved.