Class DateTimeComboPicker
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<DateTimeComboPicker>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<DateTimeComboPicker>,com.vaadin.flow.component.FocusNotifier<DateTimeComboPicker>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasPlaceholder,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimeComboPicker,,LocalDateTime>, LocalDateTime> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimeComboPicker,,LocalDateTime>, LocalDateTime> com.vaadin.flow.component.shared.HasTooltip,Serializable
LocalDateTime
value whose popup shows a month calendar and a time selector side by side
(sliding columns by default, or an analog clock via
setTimeView(TimeView)).
The format pattern defines both how the
value is displayed and parsed in the field, and which time columns are shown
in the popup: a pattern without ss shows no seconds column, a
pattern without mm shows no minutes column, and h/hh
(with a) uses a 12-hour clock with an AM/PM column.
Supported pattern letters: yyyy/yy, MM/M,
dd/d, HH/H, hh/h,
mm/m, ss/s and a. Other characters
are literals; quote literal text with single quotes.
DateTimeComboPicker picker = new DateTimeComboPicker("Meeting");
picker.setFormat("dd.MM.yyyy HH:mm");
picker.setValue(LocalDateTime.now());
picker.addValueChangeListener(e -> ...);
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default format pattern, "dd.MM.yyyy HH:mm". -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new picker with no value and the default format ("dd.MM.yyyy HH:mm").DateTimeComboPicker(String label) Creates a new picker with the given label.DateTimeComboPicker(String label, LocalDateTime initialValue) Creates a new picker with the given label and initial value. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddToActionBar(com.vaadin.flow.component.Component... components) Adds components to the start of the popup's action bar, before the Cancel/OK buttons (e.g.intGets the delay before the analog clock advances to the next view.Gets the date-time format pattern.intGets the interval between the items of the hours column.getI18n()Gets the internationalization settings.Gets the initial popup position.getMax()Gets the latest allowed date-time.getMin()Gets the earliest allowed date-time.intGets the interval between the items of the minutes column.intGets the interval between the items of the seconds column.Gets the time selector shown in the popup.protected booleanbooleanGets whether the analog clock advances to the next view automatically.booleanGets whether selections are applied immediately.booleanGets whether the popup opens on field interaction.booleanGets whether the Cancel button of the action bar is visible.booleanGets whether the clear button is visible.booleanbooleanGets whether the fullscreen (mobile) popup uses the tabbed layout.booleanGets whether the OK button of the action bar is visible.booleanisOpened()Gets whether the popup is open.booleanGets whether week numbers are shown.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) voidremoveFromActionBar(com.vaadin.flow.component.Component... components) Removes components added withaddToActionBar(Component...).voidsetAutoAdvance(boolean autoAdvance) Sets whether the analog clock automatically advances to the next view (hours to minutes to seconds) after a selection.voidsetAutoAdvanceDelay(int autoAdvanceDelayMs) Sets the delay, in milliseconds, before the analog clock advances to the next view after a selection, giving the selection time to register visually.voidsetAutoApply(boolean autoApply) Sets whether selections in the popup are applied to the value immediately.voidsetAutoOpen(boolean autoOpen) Sets whether the popup opens when the field is clicked or typed in.voidsetCancelButtonVisible(boolean cancelButtonVisible) Sets whether the Cancel button of the action bar is visible.voidsetClearButtonVisible(boolean clearButtonVisible) Sets whether a clear button is shown when the field has a value.voidsetDateDisabledFunction(String jsFunctionExpression) Sets a client-side function that determines whether a given date is disabled.voidsetErrorMessage(String errorMessage) voidSets the date-time format pattern, e.g.voidsetHourStep(int hourStep) Sets the interval between the items of the hours column, e.g.voidSets the internationalization settings.voidsetInitialPosition(LocalDateTime initialPosition) Sets the date-time that the popup shows initially, and that provides the date/time parts not yet chosen by the user, when the field has no value.voidsetInvalid(boolean invalid) voidsetManualValidation(boolean enabled) voidsetMax(LocalDateTime max) Sets the latest allowed date-time.voidsetMin(LocalDateTime min) Sets the earliest allowed date-time.voidsetMinuteStep(int minuteStep) Sets the interval between the items of the minutes column, e.g.voidsetMobileTabs(boolean mobileTabs) Sets whether the fullscreen (mobile) popup shows Date/Time tabs — one section at a time, with the value formatted in the field's format shown above — instead of stacking the calendar above the time selector.voidsetOkButtonVisible(boolean okButtonVisible) Sets whether the OK button of the action bar is visible.voidsetOpened(boolean opened) Opens or closes the popup.voidsetSecondStep(int secondStep) Sets the interval between the items of the seconds column.voidsetShowWeekNumbers(boolean showWeekNumbers) Sets whether ISO-8601 week numbers are shown in the calendar.voidsetTimeView(TimeView timeView) Sets the time selector shown in the popup: sliding columns (the default) or an analog clock face.voidsetValue(LocalDateTime value) protected voidvalidate()Validates the current value against min/max on the server.Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.component.HasPlaceholder
getPlaceholder, setPlaceholderMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Field Details
-
DEFAULT_FORMAT
The default format pattern, "dd.MM.yyyy HH:mm".- See Also:
-
-
Constructor Details
-
DateTimeComboPicker
public DateTimeComboPicker()Creates a new picker with no value and the default format ("dd.MM.yyyy HH:mm"). -
DateTimeComboPicker
Creates a new picker with the given label.- Parameters:
label- the field label
-
DateTimeComboPicker
Creates a new picker with the given label and initial value.- Parameters:
label- the field labelinitialValue- the initial value, may benull
-
-
Method Details
-
hasValidValue
protected boolean hasValidValue()Rejects client-sent property values that are not parseable ISO-8601 local date-times, instead of throwing during request processing.
- Overrides:
hasValidValuein classcom.vaadin.flow.component.AbstractSinglePropertyField<DateTimeComboPicker,LocalDateTime>
-
setValue
The value is truncated to seconds precision, matching what the component can represent and serialize.
- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimeComboPicker,LocalDateTime>, LocalDateTime> - Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<DateTimeComboPicker,LocalDateTime>
-
setFormat
Sets the date-time format pattern, e.g.dd.MM.yyyy HH:mm:ssorM/d/yyyy h:mm a. The pattern defines how the value is displayed and parsed in the field, and which time columns are shown in the popup.- Parameters:
format- the format pattern, ornullto use the default ("dd.MM.yyyy HH:mm")
-
getFormat
Gets the date-time format pattern.- Returns:
- the format pattern
-
setMin
Sets the earliest allowed date-time. Values before it make the field invalid, both client-side and in the server-side validation that runs on every value change.- Parameters:
min- the minimum value, ornullfor no limit
-
getMin
Gets the earliest allowed date-time.- Returns:
- the minimum value, or
nullif not set
-
setMax
Sets the latest allowed date-time. Values after it make the field invalid, both client-side and in the server-side validation that runs on every value change.- Parameters:
max- the maximum value, ornullfor no limit
-
getMax
Gets the latest allowed date-time.- Returns:
- the maximum value, or
nullif not set
-
setAutoOpen
public void setAutoOpen(boolean autoOpen) Sets whether the popup opens when the field is clicked or typed in. When disabled, the popup only opens from the toggle button.- Parameters:
autoOpen-trueto open the popup on field interaction
-
isAutoOpen
public boolean isAutoOpen()Gets whether the popup opens on field interaction.- Returns:
trueif auto-open is enabled
-
setOpened
public void setOpened(boolean opened) Opens or closes the popup.- Parameters:
opened-trueto open,falseto close
-
isOpened
public boolean isOpened()Gets whether the popup is open.- Returns:
trueif the popup is open
-
setClearButtonVisible
public void setClearButtonVisible(boolean clearButtonVisible) Sets whether a clear button is shown when the field has a value.- Parameters:
clearButtonVisible-trueto show the clear button
-
isClearButtonVisible
public boolean isClearButtonVisible()Gets whether the clear button is visible.- Returns:
trueif the clear button is visible
-
setHourStep
public void setHourStep(int hourStep) Sets the interval between the items of the hours column, e.g. 6 shows 00, 06, 12, 18. Values that divide 24 evenly produce a uniform column.- Parameters:
hourStep- the hour interval, at least 1
-
getHourStep
public int getHourStep()Gets the interval between the items of the hours column.- Returns:
- the hour interval
-
setMinuteStep
public void setMinuteStep(int minuteStep) Sets the interval between the items of the minutes column, e.g. 5 shows 00, 05, 10, ... 55. Values that divide 60 evenly produce a uniform column.- Parameters:
minuteStep- the minute interval, at least 1
-
getMinuteStep
public int getMinuteStep()Gets the interval between the items of the minutes column.- Returns:
- the minute interval
-
setSecondStep
public void setSecondStep(int secondStep) Sets the interval between the items of the seconds column.- Parameters:
secondStep- the second interval, at least 1
-
getSecondStep
public int getSecondStep()Gets the interval between the items of the seconds column.- Returns:
- the second interval
-
setDateDisabledFunction
Sets a client-side function that determines whether a given date is disabled. Disabled dates cannot be selected in the calendar and make the field invalid.The argument must be a JavaScript function expression that receives a
{ day, month, year }object (wheremonthis 0-based) and returnstrueto disable the date. Example disabling weekends:picker.setDateDisabledFunction( "(d) => [0, 6].includes(new Date(d.year, d.month, d.day).getDay())");Note: the expression is evaluated in the browser. Since the function runs client-side, always re-validate values on the server when the dates carry security or business meaning. Passing
nullremoves the function.Security: the expression is injected into the page as JavaScript, equivalent in power to
Element.executeJs. It must be a developer-authored constant — never build it from user or request-derived input, or you create a script-injection (XSS) vulnerability.- Parameters:
jsFunctionExpression- a JavaScript function expression, ornullto remove
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
setInitialPosition
Sets the date-time that the popup shows initially, and that provides the date/time parts not yet chosen by the user, when the field has no value. Defaults to the current date-time.- Parameters:
initialPosition- the initial position, ornullto use the current date-time
-
getInitialPosition
Gets the initial popup position.- Returns:
- the initial position, or
nullif not set
-
setAutoApply
public void setAutoApply(boolean autoApply) Sets whether selections in the popup are applied to the value immediately. By default this is disabled: selections are staged and the popup shows a Cancel/OK action bar; only pressing OK applies the staged selection, while Cancel, Escape or closing the popup discards it. When enabled, every selection updates the value directly and the action bar is hidden.- Parameters:
autoApply-trueto apply selections immediately
-
isAutoApply
public boolean isAutoApply()Gets whether selections are applied immediately.- Returns:
trueif selections are applied immediately
-
setOkButtonVisible
public void setOkButtonVisible(boolean okButtonVisible) Sets whether the OK button of the action bar is visible. Visible by default. Hiding both default buttons leaves only content added withaddToActionBar(Component...).- Parameters:
okButtonVisible-falseto hide the OK button
-
isOkButtonVisible
public boolean isOkButtonVisible()Gets whether the OK button of the action bar is visible.- Returns:
trueif the OK button is visible
-
setCancelButtonVisible
public void setCancelButtonVisible(boolean cancelButtonVisible) Sets whether the Cancel button of the action bar is visible. Visible by default.- Parameters:
cancelButtonVisible-falseto hide the Cancel button
-
isCancelButtonVisible
public boolean isCancelButtonVisible()Gets whether the Cancel button of the action bar is visible.- Returns:
trueif the Cancel button is visible
-
addToActionBar
public void addToActionBar(com.vaadin.flow.component.Component... components) Adds components to the start of the popup's action bar, before the Cancel/OK buttons (e.g. a "Now" shortcut button). Only visible while the action bar is shown, i.e. when auto-apply is disabled (the default). Remove components withremoveFromActionBar(Component...).- Parameters:
components- the components to add
-
removeFromActionBar
public void removeFromActionBar(com.vaadin.flow.component.Component... components) Removes components added withaddToActionBar(Component...).- Parameters:
components- the components to remove
-
setTimeView
Sets the time selector shown in the popup: sliding columns (the default) or an analog clock face.- Parameters:
timeView- the time view, notnull
-
getTimeView
Gets the time selector shown in the popup.- Returns:
- the time view
-
setAutoAdvance
public void setAutoAdvance(boolean autoAdvance) Sets whether the analog clock automatically advances to the next view (hours to minutes to seconds) after a selection. Enabled by default. When disabled, the user switches views from the digital readout above the dial. Only applies when the time view isTimeView.CLOCK.- Parameters:
autoAdvance-trueto advance automatically
-
isAutoAdvance
public boolean isAutoAdvance()Gets whether the analog clock advances to the next view automatically.- Returns:
trueif auto-advance is enabled
-
setAutoAdvanceDelay
public void setAutoAdvanceDelay(int autoAdvanceDelayMs) Sets the delay, in milliseconds, before the analog clock advances to the next view after a selection, giving the selection time to register visually. The default is 300 ms;0advances immediately. Only applies when the time view isTimeView.CLOCKand auto-advance is enabled.- Parameters:
autoAdvanceDelayMs- the delay in milliseconds, not negative
-
getAutoAdvanceDelay
public int getAutoAdvanceDelay()Gets the delay before the analog clock advances to the next view.- Returns:
- the delay in milliseconds
-
setMobileTabs
public void setMobileTabs(boolean mobileTabs) Sets whether the fullscreen (mobile) popup shows Date/Time tabs — one section at a time, with the value formatted in the field's format shown above — instead of stacking the calendar above the time selector. Enabled by default; only applies when the format has both a date and a time part. When disabled, the sections stack vertically. The tab labels can be localized withDateTimeComboPickerI18n.setDateTab(String)andDateTimeComboPickerI18n.setTimeTab(String).- Parameters:
mobileTabs-trueto use the tabbed fullscreen layout
-
isMobileTabs
public boolean isMobileTabs()Gets whether the fullscreen (mobile) popup uses the tabbed layout.- Returns:
trueif the Date/Time tabs are enabled
-
setShowWeekNumbers
public void setShowWeekNumbers(boolean showWeekNumbers) Sets whether ISO-8601 week numbers are shown in the calendar. Only supported when the first day of the week is Monday (i18n.firstDayOfWeek= 1).- Parameters:
showWeekNumbers-trueto show week numbers
-
isShowWeekNumbers
public boolean isShowWeekNumbers()Gets whether week numbers are shown.- Returns:
trueif week numbers are shown
-
setErrorMessage
- Specified by:
setErrorMessagein interfacecom.vaadin.flow.component.HasValidation
-
getErrorMessage
- Specified by:
getErrorMessagein interfacecom.vaadin.flow.component.HasValidation
-
setInvalid
public void setInvalid(boolean invalid) - Specified by:
setInvalidin interfacecom.vaadin.flow.component.HasValidation
-
isInvalid
public boolean isInvalid()Note: this reflects the server-known invalid state (set by
setInvalid(boolean)and the built-in server-side min/max validation). Constraints evaluated only in the browser — unparseable typed text, required-but-empty and the date-disabled function — are not reported back to the server and are not visible here.- Specified by:
isInvalidin interfacecom.vaadin.flow.component.HasValidation
-
setManualValidation
public void setManualValidation(boolean enabled) - Specified by:
setManualValidationin interfacecom.vaadin.flow.component.HasValidation
-
validate
protected void validate()Validates the current value against min/max on the server. Runs automatically on every value change and when min/max change; does nothing when manual validation is enabled (e.g. byBinder).The server only toggles the invalid state; the error message is always chosen by the client-side validation, which knows the failed constraint and the configured i18n messages. Note that a date-disabled function set with
setDateDisabledFunction(String)is evaluated only in the browser and is not part of this server-side validation. -
setI18n
Sets the internationalization settings.- Parameters:
i18n- the i18n object, notnull
-
getI18n
Gets the internationalization settings.Note: updating the returned object does not update the component; call
setI18n(DateTimeComboPickerI18n)to apply changes.- Returns:
- the i18n object, or
nullif not set
-