T
- type of date (LocalDate
or LocalDateTime
).R
- resolution enumeration typepublic abstract class AbstractDateField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>,R extends Enum<R>> extends AbstractField<T> implements FieldEvents.FocusNotifier, FieldEvents.BlurNotifier
LocalDate
as an input value.HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
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 |
---|
AbstractDateField(R resolution)
Constructs an empty
AbstractDateField with no caption and
specified resolution . |
AbstractDateField(String caption,
R resolution)
Constructs an empty
AbstractDateField with caption. |
AbstractDateField(String caption,
T value,
R resolution)
Constructs a new
AbstractDateField with the given caption and
initial text contents. |
Modifier and Type | Method and Description |
---|---|
Registration |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
Registration |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
protected abstract T |
adjustToResolution(T date,
R resolution)
Adjusts the given date to the given resolution.
|
protected boolean |
afterDate(T value,
T base)
Checks if
value is after base or not. |
void |
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the
client.
|
protected abstract T |
buildDate(Map<R,Integer> resolutionValues)
Builds date by the given
resolutionValues which is a map whose
keys are resolution and integer values. |
protected abstract T |
convertFromDate(Date date)
Converts
Date to date type T . |
protected T |
convertFromDateString(String temporalStr)
Parses string representation of date range limit into date type.
|
protected abstract Date |
convertToDate(T date)
Converts the object of type
T to Date . |
protected String |
convertToDateString(T temporal)
Converts date range limit into string representation.
|
protected void |
doSetValue(T value)
Sets the value of this field.
|
protected abstract String |
formatDate(T value)
Formats date according to the components locale.
|
void |
getAssistiveLabel(AbstractDateFieldState.AccessibleElement element)
Gets the assistive label of a calendar navigation element.
|
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.
|
protected abstract int |
getDatePart(T date,
R resolution)
Returns a date integer value part for the given
date for the
given resolution . |
String |
getDateStyle(LocalDate date)
Returns the custom style name that corresponds with the given date's
calendar cell.
|
Map<LocalDate,String> |
getDateStyles()
Returns a map from dates to custom style names in each date's calendar
cell.
|
Validator<T> |
getDefaultValidator()
Returns a validator that checks the internal state of the HasValue.
|
T |
getDefaultValue()
Returns the current default value.
|
String |
getParseErrorMessage()
Return the error message that is shown if the user inputted value can't
be parsed into a Date object.
|
T |
getRangeEnd()
Returns the precise rangeEnd used.
|
T |
getRangeStart()
Returns the precise rangeStart used.
|
protected abstract RangeValidator<T> |
getRangeValidator()
Returns a custom date range validator which is applicable for the type
T . |
R |
getResolution()
Gets the resolution.
|
protected AbstractDateFieldState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected AbstractDateFieldState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
T |
getValue()
Returns the current value of this object.
|
ZoneId |
getZoneId()
|
protected Result<T> |
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 lenient.
|
boolean |
isPreventInvalidInput()
Check whether value change is emitted when user input value does not meet
integrated range validator.
|
boolean |
isShowISOWeekNumbers()
Checks whether ISO 8601 week numbers are shown in the date selector.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the component state from the given design.
|
protected T |
reconstructDateFromFields(Map<String,Integer> resolutions,
T oldDate)
Construct a date object from the individual field values received from
the client.
|
void |
setAssistiveLabel(AbstractDateFieldState.AccessibleElement element,
String label)
Sets the assistive label for a calendar navigation element.
|
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.
|
void |
setDateStyle(LocalDate date,
String styleName)
Sets a custom style name for the given date's calendar cell.
|
void |
setDaylightSavingTimeRange(int startYear,
int endYear)
Sets
startYear and endYear : the start and end years (both
inclusive) between which to calculate the daylight-saving time zone
transition dates. |
void |
setDefaultValue(T defaultValue)
Sets the default value for the field.
|
void |
setLenient(boolean lenient)
Specifies whether or not date/time interpretation in component is to be
lenient.
|
void |
setLocale(Locale locale)
Sets the locale of this component.
|
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 |
setPreventInvalidInput(boolean preventInvalidInput)
Control whether value change event is emitted when user input value does
not meet the integrated range validator.
|
void |
setRangeEnd(T endDate)
Sets the end range for this component.
|
void |
setRangeStart(T startDate)
Sets the start range for this component.
|
void |
setResolution(R resolution)
Sets the resolution of the DateField.
|
void |
setShowISOWeekNumbers(boolean showWeekNumbers)
Sets the visibility of ISO 8601 week numbers in the date selector.
|
void |
setValue(T value)
Sets the value of this object.
|
void |
setZoneId(ZoneId zoneId)
|
protected abstract T |
toType(TemporalAccessor temporalAccessor)
Converts a temporal value into field-specific data type.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
addValueChangeListener, createValueChange, focus, getCustomAttributes, getTabIndex, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setTabIndex, setValue
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, 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, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, 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, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
clear, getEmptyValue, getOptionalValue, isEmpty
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
public AbstractDateField(R resolution)
AbstractDateField
with no caption and
specified resolution
.resolution
- initial resolution for the field, not null
public AbstractDateField(String caption, R resolution)
AbstractDateField
with caption.caption
- the caption of the datefieldresolution
- initial resolution for the field, not null
public AbstractDateField(String caption, T value, R resolution)
AbstractDateField
with the given caption and
initial text contents.caption
- the caption String
for the editor.value
- the date/time value.resolution
- initial resolution for the field, not null
public void beforeClientResponse(boolean initial)
ClientConnector
beforeClientResponse
in interface ClientConnector
beforeClientResponse
in class AbstractComponent
initial
- true
if the client-side connector will be created
and initialized after this method has been invoked.
false
if there is already an initialized
client-side connector.protected T reconstructDateFromFields(Map<String,Integer> resolutions, T oldDate)
resolutions
- map of time unit (resolution) name and value, the key is the
resolution name e.g. "HOUR", "MINUTE", the value can be
null
oldDate
- used as a fallback to get needed values if they are not
defined in the specified resolutions
public void setRangeStart(T startDate)
startDate
is set to null
, any value before
endDate
will be accepted by the range
Note: Negative, i.e. BC dates are not supported.
Note: It's usually recommended to use only one of the following at the same time: Range validator with Binder or DateField's setRangeStart check.
startDate
- - 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 String getDateOutOfRangeMessage()
setDateOutOfRangeMessage(String)
public R getResolution()
public void setResolution(R resolution)
DateResolution.DAY
since Vaadin 7.0.resolution
- the resolution to set, not null
public void setRangeEnd(T endDate)
endDate
is set to null
, any value after
startDate
will be accepted by the range.
Note: It's usually recommended to use only one of the following at the same time: Range validator with Binder or DateField's setRangeEnd check.
endDate
- the allowed range's end date (inclusive, based on the current
resolution)public T getRangeStart()
null
.protected T convertFromDateString(String temporalStr)
temporalStr
- the string representationAbstractDateFieldState.rangeStart
,
AbstractDateFieldState.rangeEnd
protected abstract T toType(TemporalAccessor temporalAccessor)
temporalAccessor
- - source valueprotected String convertToDateString(T temporal)
temporal
- the valueAbstractDateFieldState.rangeStart
,
AbstractDateFieldState.rangeEnd
protected boolean afterDate(T value, T base)
value
is after base
or not.value
- temporal valuebase
- temporal value to compare totrue
if value
is after base
,
false
otherwisepublic T getRangeEnd()
null
.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 set, can be null
com.vaadin.ui.AbstractComponent#setLocale(Locale))
public String getDateFormat()
null
if default formatting from Component.getLocale()
is
used.public void setZoneId(ZoneId zoneId)
zoneId
- the zone idpublic void setDaylightSavingTimeRange(int startYear, int endYear)
startYear
and endYear
: the start and end years (both
inclusive) between which to calculate the daylight-saving time zone
transition dates. Both parameters are used when 'z
' is included
inside the setDateFormat(String)
, they would have no effect
otherwise. Specifically, these parameters determine the range of years in
which zone names are are adjusted to show the daylight saving names.
If no values are provided, by default startYear
is set to
, and endYear
is set to
years into the future from the current
date.startYear
- the start year of DST transitionsendYear
- the end year of DST transitionspublic void setLocale(Locale locale)
AbstractComponent
// Component for which the locale is meaningful InlineDateField date = new InlineDateField("Datum"); // German language specified with ISO 639-1 language // code and ISO 3166-1 alpha-2 country code. date.setLocale(new Locale("de", "DE")); date.setResolution(DateField.RESOLUTION_DAY); layout.addComponent(date);
setLocale
in class AbstractComponent
locale
- the locale to become this component's locale.public ZoneId getZoneId()
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()
true
if the interpretation mode of this calendar is
lenient; false
otherwise.setLenient(boolean)
public T getValue()
HasValue
Implementation note: the implementing class should document whether null values may be returned or not.
getValue
in interface HasValue<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
public T getDefaultValue()
setDefaultValue(Temporal)
public void setDefaultValue(T defaultValue)
defaultValue
- the default value, may be null
public void setValue(T value)
getValue()
, fires a ValueChangeEvent
.setValue
in interface HasValue<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
setValue
in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
value
- the new value, may be null
IllegalArgumentException
- if the value is not within range boundsprotected abstract T adjustToResolution(T date, R resolution)
date
- the date to adjust, can be null
resolution
- the resolution to be used in the adjustment, can be
null
null
if the given date, resolution, or both were
null
public boolean isShowISOWeekNumbers()
public void setShowISOWeekNumbers(boolean showWeekNumbers)
showWeekNumbers
- true if week numbers should be shown, false otherwise.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
- the default parsing error messagegetParseErrorMessage()
,
handleUnparsableDateString(String)
public Registration addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifier
FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.addFocusListener
in interface FieldEvents.FocusNotifier
listener
- the focus listener to add, not nullFieldEvents.FocusListener
,
Registration
public Registration addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifier
BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.addBlurListener
in interface FieldEvents.BlurNotifier
listener
- the blur listener to add, not nullFieldEvents.BlurListener
,
Registration
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<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designprotected abstract String formatDate(T value)
value
- the date or null
null
public 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<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
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 designprotected Result<T> handleUnparsableDateString(String dateString)
getParseErrorMessage()
.
This can be overridden to handle conversions, to return a result with
null
value (equivalent to empty input) or to return a custom
error.dateString
- date string to handleprotected AbstractDateFieldState getState()
AbstractComponent
getState
in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
protected AbstractDateFieldState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
protected void doSetValue(T value)
AbstractField
IllegalArgumentException
if the value is invalid. Typically saves
the value to shared state.doSetValue
in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
value
- the new value of the fieldprotected abstract int getDatePart(T date, R resolution)
date
for the
given resolution
.date
- the given date, can be null
resolution
- the resolution to extract a value from the date by, not
null
protected abstract T buildDate(Map<R,Integer> resolutionValues)
resolutionValues
which is a map whose
keys are resolution and integer values.
This is the opposite to getDatePart(Temporal, Enum)
.
resolutionValues
- date values to construct a dateprotected abstract RangeValidator<T> getRangeValidator()
T
.protected abstract T convertFromDate(Date date)
Date
to date type T
.date
- a date to convertT
representing the date
protected abstract Date convertToDate(T date)
date
- the date of type T
Date
public Validator<T> getDefaultValidator()
HasValue
Binder
and can be seen as a validation failure.getDefaultValidator
in interface HasValue<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>
Binder.validate()
public void setDateStyle(LocalDate date, String styleName)
Sets a custom style name for the given date's calendar cell. Setting the
style name will override any previous style names that have been set for
that date, but can contain several actual style names separated by space.
Setting the custom style name null
will only remove the previous
custom style name.
This logic is entirely separate from AbstractComponent.setStyleName(String)
Usage examples:
setDateStyle(LocalDate.now(), "teststyle");
setDateStyle(LocalDate.now(), "teststyle1 teststyle2");
date
- which date cell to modify, not null
styleName
- the custom style name(s) for given date, null
to clear
custom style name(s)public String getDateStyle(LocalDate date)
date
- which date cell's custom style name(s) to return, not
null
null
otherwisesetDateStyle(LocalDate, String)
public Map<LocalDate,String> getDateStyles()
setDateStyle(LocalDate, String)
public void setAssistiveLabel(AbstractDateFieldState.AccessibleElement element, String label)
aria-label
attribute for the element which is used by screen
reading software.element
- the element for which to set the label. Not null
.label
- the assistive label to setpublic void getAssistiveLabel(AbstractDateFieldState.AccessibleElement element)
element
- the element of which to get the assistive labelpublic void setPreventInvalidInput(boolean preventInvalidInput)
preventInvalidInput
- Set to false to disable the value change event.public boolean isPreventInvalidInput()
Copyright © 2021 Vaadin Ltd. All rights reserved.