com.vaadin.flow.component.datetimepicker.
Class DateTimePicker
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<DateTimePicker,LocalDateTime>
-
- com.vaadin.flow.component.datetimepicker.DateTimePicker
-
All Implemented Interfaces:
AttachNotifier, BlurNotifier<DateTimePicker>, DetachNotifier, Focusable<DateTimePicker>, FocusNotifier<DateTimePicker>, HasElement, HasEnabled, HasSize, HasStyle, HasTheme, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>, Serializable
@Tag(value="vaadin-date-time-picker") @HtmlImport(value="frontend://bower_components/vaadin-date-time-picker/src/vaadin-date-time-picker.html") @NpmPackage(value="@vaadin/vaadin-date-time-picker", version="1.2.0") @JsModule(value="@vaadin/vaadin-date-time-picker/src/vaadin-date-time-picker.js") public class DateTimePicker extends AbstractField<DateTimePicker,LocalDateTime> implements HasStyle, HasSize, HasTheme, HasValidation, Focusable<DateTimePicker>
Server-side component that encapsulates the functionality of the
vaadin-date-time-picker
web component.See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,V>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor and Description DateTimePicker()
Default constructor.
DateTimePicker(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener
.DateTimePicker(LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected date time in current UI locale format.
DateTimePicker(LocalDateTime initialDateTime, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected date time in current UI locale format and a
ValueChangeListener
.DateTimePicker(LocalDateTime initialDateTime, Locale locale)
Convenience constructor to create a date time picker with pre-selected date time and locale setup.
DateTimePicker(String label)
Convenience constructor to create a date time picker with a label.
DateTimePicker(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener
and a label.DateTimePicker(String label, LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected date and time in current UI locale format and a label.
DateTimePicker(String label, LocalDateTime initialDateTime, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected date and time in current UI locale format, a
ValueChangeListener
and a label.
-
Method Summary
All Methods Modifier and Type Method and Description void
addThemeName(String themeName)
Adds a theme name to this component.
void
addThemeNames(String... themeNames)
Adds one or more theme names to this component.
DatePicker.DatePickerI18n
getDatePickerI18n()
Gets the internationalization object previously set for this component.
String
getDatePlaceholder()
Gets the placeholder string of the date field.
String
getErrorMessage()
Gets the error message to display when the input is invalid.
String
getLabel()
Gets the label of this field.
Locale
getLocale()
Gets the Locale for this DateTimePicker
LocalDateTime
getMax()
Gets the maximum date and time in the date time picker.
LocalDateTime
getMin()
Gets the minimum date and time in the date time picker.
Duration
getStep()
Gets the step of the time picker.
String
getTimePlaceholder()
Gets the placeholder string of the time field.
boolean
isAutoOpen()
When auto open is enabled, the dropdown will open when the field is clicked.
boolean
isInvalid()
Gets the validity indication of the date time picker output.
boolean
isWeekNumbersVisible()
Get the state of
showWeekNumbers
property of the date picker.boolean
removeThemeName(String themeName)
Removes a theme name from this component.
void
removeThemeNames(String... themeNames)
Removes one or more theme names from component.
void
setAutoOpen(boolean autoOpen)
When auto open is enabled, the dropdown will open when the field is clicked.
void
setDatePickerI18n(DatePicker.DatePickerI18n i18n)
Sets the internationalization properties for the date picker inside this component.
void
setDatePlaceholder(String placeholder)
Sets a placeholder string for the date field.
void
setErrorMessage(String errorMessage)
Sets the error message to display when the input is invalid.
void
setInvalid(boolean invalid)
Sets the validity indication of the date time picker output.
void
setLabel(String label)
Sets the label for this field.
void
setLocale(Locale locale)
Set the Locale for the DateTimePicker.
void
setMax(LocalDateTime max)
Sets the maximum date and time in the date time picker.
void
setMin(LocalDateTime min)
Sets the minimum date and time in the date time picker.
protected void
setPresentationValue(LocalDateTime newPresentationValue)
Updates the presentation of this field to display the provided value.
void
setReadOnly(boolean readOnly)
Sets the read-only mode of this
HasValue
to given mode.void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets whether the date time picker is marked as input required.
void
setStep(Duration step)
Sets the
step
property of the time picker using duration.void
setThemeName(String themeName)
Sets the theme names of this component.
void
setThemeName(String themeName, boolean set)
Sets or removes the given theme name for this component.
void
setTimePlaceholder(String placeholder)
Set a placeholder string for the time field.
void
setValue(LocalDateTime value)
Sets the value of this object.
void
setWeekNumbersVisible(boolean weekNumbersVisible)
Show or hide the week numbers in the date picker.
protected void
validate()
Performs server-side validation of the current value.
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEquals
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
getThemeName, getThemeNames, hasThemeName
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible
-
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
DateTimePicker
public DateTimePicker()
Default constructor.
-
DateTimePicker
public DateTimePicker(String label)
Convenience constructor to create a date time picker with a label.
Parameters:
label
- the label describing the date time pickerSee Also:
-
DateTimePicker
public DateTimePicker(String label, LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected date and time in current UI locale format and a label.
Parameters:
label
- the label describing the date time pickerinitialDateTime
- the pre-selected date time in the pickerSee Also:
-
DateTimePicker
public DateTimePicker(LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected date time in current UI locale format.
Parameters:
initialDateTime
- the pre-selected date time in the picker
-
DateTimePicker
public DateTimePicker(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener
.Parameters:
listener
- the listener to receive value change eventsSee Also:
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)
-
DateTimePicker
public DateTimePicker(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener
and a label.Parameters:
label
- the label describing the date time pickerlistener
- the listener to receive value change eventsSee Also:
setLabel(String)
,AbstractField.addValueChangeListener(HasValue.ValueChangeListener)
-
DateTimePicker
public DateTimePicker(LocalDateTime initialDateTime, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected date time in current UI locale format and a
ValueChangeListener
.Parameters:
initialDateTime
- the pre-selected date time in the pickerlistener
- the listener to receive value change eventsSee Also:
setValue(LocalDateTime)
,AbstractField.addValueChangeListener(HasValue.ValueChangeListener)
-
DateTimePicker
public DateTimePicker(String label, LocalDateTime initialDateTime, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected date and time in current UI locale format, a
ValueChangeListener
and a label.Parameters:
label
- the label describing the date time pickerinitialDateTime
- the pre-selected date time in the pickerlistener
- the listener to receive value change eventsSee Also:
setLabel(String)
,setValue(LocalDateTime)
,AbstractField.addValueChangeListener(HasValue.ValueChangeListener)
-
DateTimePicker
public DateTimePicker(LocalDateTime initialDateTime, Locale locale)
Convenience constructor to create a date time picker with pre-selected date time and locale setup.
Parameters:
initialDateTime
- the pre-selected date time in the pickerlocale
- the locale for the date time picker
-
-
Method Detail
-
setValue
public void setValue(LocalDateTime value)
Description copied from interface:
HasValue
Sets the value of this object. If the new value is not equal to
getValue()
, fires a value change event. May throwIllegalArgumentException
if the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not, and override
HasValue.getEmptyValue()
if the empty value is notnull
.Specified by:
setValue
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>
Overrides:
setValue
in classAbstractField<DateTimePicker,LocalDateTime>
Parameters:
value
- the new value
-
setPresentationValue
protected void setPresentationValue(LocalDateTime newPresentationValue)
Description copied from class:
AbstractField
Updates the presentation of this field to display the provided value. Subclasses should override this method to show the value to the user. This is typically done by setting an element property or by applying changes to child components.
If
AbstractField.setModelValue(Object, boolean)
is called from within this method, the value of the last invocation will be used as the model value instead of the value passed to this method. In this caseAbstractField.setPresentationValue(Object)
will not be called again. Changing the provided value might be useful if the provided value is sanitized.See
AbstractField
for an overall description on the difference between model values and presentation values.Specified by:
setPresentationValue
in classAbstractField<DateTimePicker,LocalDateTime>
Parameters:
newPresentationValue
- the new value to show
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:
HasValue
Sets the read-only mode of this
HasValue
to given mode. The user can't change the value when in read-only mode.A
HasValue
with a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.Specified by:
setReadOnly
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>
Specified by:
setReadOnly
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>
Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
setLabel
public void setLabel(String label)
Sets the label for this field.
Parameters:
label
- the String value to set
-
getLabel
public String getLabel()
Gets the label of this field.
Returns:
the
label
property of the date time picker
-
setDatePlaceholder
public void setDatePlaceholder(String placeholder)
Sets a placeholder string for the date field.
Parameters:
placeholder
- the String value to set
-
getDatePlaceholder
public String getDatePlaceholder()
Gets the placeholder string of the date field.
Returns:
the
placeholder
property of the date picker
-
setTimePlaceholder
public void setTimePlaceholder(String placeholder)
Set a placeholder string for the time field.
Parameters:
placeholder
- the String value to set
-
getTimePlaceholder
public String getTimePlaceholder()
Gets the placeholder string of the time field.
Returns:
the
placeholder
property of the time picker
-
setStep
public void setStep(Duration step)
Sets the
step
property of the time picker using duration. It specifies the intervals for the displayed items in the time picker dropdown and also the displayed time format.The set step needs to evenly divide a day or an hour and has to be larger than 0 milliseconds. By default, the format is
hh:mm
(same as *Duration.ofHours(1)
If the step is less than 60 seconds, the format will be changed to
hh:mm:ss
and it can be inhh:mm:ss.fff
format, when the step is less than 1 second.NOTE: If the step is less than 900 seconds, the dropdown is hidden.
NOTE: changing the step to a larger duration can cause a new
HasValue.ValueChangeEvent
to be fired if some parts (eg. seconds) is discarded from the value.Parameters:
step
- the step to set, notnull
and should divide a day or an hour evenly
-
getStep
public Duration getStep()
Gets the step of the time picker.
Returns:
the
step
property from the picker, unit seconds
-
setWeekNumbersVisible
public void setWeekNumbersVisible(boolean weekNumbersVisible)
Show or hide the week numbers in the date picker. By default the week numbers are not shown.
Set true to display ISO-8601 week numbers in the calendar.
Note that displaying of week numbers is only supported when i18n.firstDayOfWeek is 1 (Monday).
Parameters:
weekNumbersVisible
- the boolean value to setSee Also:
#setDatePickerI18n(DatePickerI18n)
,DatePicker.DatePickerI18n.setFirstDayOfWeek(int)
-
isWeekNumbersVisible
public boolean isWeekNumbersVisible()
Get the state of
showWeekNumbers
property of the date picker.Returns:
the
showWeekNumbers
property from the date picker
-
setLocale
public void setLocale(Locale locale)
Set the Locale for the DateTimePicker. The displayed date and time will be matched to the format used in that locale.
Parameters:
locale
- the locale to set to the DateTimePicker, cannot be null
-
getLocale
public Locale getLocale()
Gets the Locale for this DateTimePicker
-
addThemeName
public void addThemeName(String themeName)
Adds a theme name to this component.
Specified by:
addThemeName
in interfaceHasTheme
Parameters:
themeName
- the theme name to add, notnull
-
removeThemeName
public boolean removeThemeName(String themeName)
Removes a theme name from this component.
Specified by:
removeThemeName
in interfaceHasTheme
Parameters:
themeName
- the theme name to remove, notnull
Returns:
true
if the theme name was removed,false
if the theme list didn't contain the theme name
-
setThemeName
public void setThemeName(String themeName)
Sets the theme names of this component. This method overwrites any previous set theme names.
Specified by:
setThemeName
in interfaceHasTheme
Parameters:
themeName
- a space-separated string of theme names to set, or empty string to remove all theme names
-
setThemeName
public void setThemeName(String themeName, boolean set)
Sets or removes the given theme name for this component.
Specified by:
setThemeName
in interfaceHasTheme
Parameters:
themeName
- the theme name to set or remove, notnull
set
-true
to set the theme name,false
to remove it
-
addThemeNames
public void addThemeNames(String... themeNames)
Adds one or more theme names to this component. Multiple theme names can be specified by using multiple parameters.
Specified by:
addThemeNames
in interfaceHasTheme
Parameters:
themeNames
- the theme name or theme names to be added to the component
-
removeThemeNames
public void removeThemeNames(String... themeNames)
Removes one or more theme names from component. Multiple theme names can be specified by using multiple parameters.
Specified by:
removeThemeNames
in interfaceHasTheme
Parameters:
themeNames
- the theme name or theme names to be removed from the component
-
setErrorMessage
public void setErrorMessage(String errorMessage)
Sets the error message to display when the input is invalid.
Specified by:
setErrorMessage
in interfaceHasValidation
Parameters:
errorMessage
- a new error message
-
getErrorMessage
public String getErrorMessage()
Gets the error message to display when the input is invalid.
Specified by:
getErrorMessage
in interfaceHasValidation
Returns:
the current error message
-
setInvalid
public void setInvalid(boolean invalid)
Sets the validity indication of the date time picker output.
Specified by:
setInvalid
in interfaceHasValidation
Parameters:
invalid
- new value for component input validity
-
isInvalid
public boolean isInvalid()
Gets the validity indication of the date time picker output.
Specified by:
isInvalid
in interfaceHasValidation
Returns:
the current validity indication.
-
validate
protected void validate()
Performs server-side validation of the current value. This is needed because it is possible to circumvent the client-side validation constraints using browser development tools.
-
setMin
public void setMin(LocalDateTime min)
Sets the minimum date and time in the date time picker. Dates and times before that will be disabled in the popups.
Parameters:
min
- the minimum date and time that is allowed to be set, ornull
to remove any minimum constraints
-
getMin
public LocalDateTime getMin()
Gets the minimum date and time in the date time picker. Dates and times before that will be disabled in the popups.
Returns:
the minimum date and time that is allowed to be set, or
null
if there's no minimum
-
setMax
public void setMax(LocalDateTime max)
Sets the maximum date and time in the date time picker. Dates and times above that will be disabled in the popups.
Parameters:
max
- the maximum date and time that is allowed to be set, ornull
to remove any minimum constraints
-
getMax
public LocalDateTime getMax()
Gets the maximum date and time in the date time picker. Dates and times above that will be disabled in the popups.
Returns:
the maximum date and time that is allowed to be set, or
null
if there's no minimum
-
getDatePickerI18n
public DatePicker.DatePickerI18n getDatePickerI18n()
Gets the internationalization object previously set for this component. Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using
DateTimePicker#setDatePickerI18n(DatePickerI18n)
Returns:
the i18n object. It will be
null
, If the i18n properties weren't set.
-
setDatePickerI18n
public void setDatePickerI18n(DatePicker.DatePickerI18n i18n)
Sets the internationalization properties for the date picker inside this component.
Parameters:
i18n
- the internationalized properties, notnull
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets whether the date time picker is marked as input required.
Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>
Specified by:
setRequiredIndicatorVisible
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>
Parameters:
requiredIndicatorVisible
- the value of the requiredIndicatorVisible to be set
-
setAutoOpen
public void setAutoOpen(boolean autoOpen)
When auto open is enabled, the dropdown will open when the field is clicked.
Parameters:
autoOpen
- Value for the auto open property,
-
isAutoOpen
public boolean isAutoOpen()
When auto open is enabled, the dropdown will open when the field is clicked.
Returns:
true
if auto open is enabled.false
otherwise. Default istrue
-
-