Class DateTimeComboPicker

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,T>
com.vaadin.flow.component.AbstractSinglePropertyField<DateTimeComboPicker,LocalDateTime>
org.vaadin.addons.krissvaa.datetimecombopicker.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

@Tag("date-time-combo-picker") @JsModule("./date-time-combo-picker/date-time-combo-picker-lumo.js") public class DateTimeComboPicker extends com.vaadin.flow.component.AbstractSinglePropertyField<DateTimeComboPicker,LocalDateTime> implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.HasPlaceholder, com.vaadin.flow.component.Focusable<DateTimeComboPicker>
A combined date and time picker: a single field with a 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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default format pattern, "dd.MM.yyyy HH:mm".
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new picker with no value and the default format ("dd.MM.yyyy HH:mm").
    Creates a new picker with the given label.
    Creates a new picker with the given label and initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    int
    Gets the delay before the analog clock advances to the next view.
     
    Gets the date-time format pattern.
    int
    Gets the interval between the items of the hours column.
    Gets the internationalization settings.
    Gets the initial popup position.
    Gets the latest allowed date-time.
    Gets the earliest allowed date-time.
    int
    Gets the interval between the items of the minutes column.
    int
    Gets the interval between the items of the seconds column.
    Gets the time selector shown in the popup.
    protected boolean
    boolean
    Gets whether the analog clock advances to the next view automatically.
    boolean
    Gets whether selections are applied immediately.
    boolean
    Gets whether the popup opens on field interaction.
    boolean
    Gets whether the Cancel button of the action bar is visible.
    boolean
    Gets whether the clear button is visible.
    boolean
    boolean
    Gets whether the fullscreen (mobile) popup uses the tabbed layout.
    boolean
    Gets whether the OK button of the action bar is visible.
    boolean
    Gets whether the popup is open.
    boolean
    Gets whether week numbers are shown.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    removeFromActionBar(com.vaadin.flow.component.Component... components)
    Removes components added with addToActionBar(Component...).
    void
    setAutoAdvance(boolean autoAdvance)
    Sets whether the analog clock automatically advances to the next view (hours to minutes to seconds) after a selection.
    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.
    void
    setAutoApply(boolean autoApply)
    Sets whether selections in the popup are applied to the value immediately.
    void
    setAutoOpen(boolean autoOpen)
    Sets whether the popup opens when the field is clicked or typed in.
    void
    setCancelButtonVisible(boolean cancelButtonVisible)
    Sets whether the Cancel button of the action bar is visible.
    void
    setClearButtonVisible(boolean clearButtonVisible)
    Sets whether a clear button is shown when the field has a value.
    void
    setDateDisabledFunction(String jsFunctionExpression)
    Sets a client-side function that determines whether a given date is disabled.
    void
    setErrorMessage(String errorMessage)
     
    void
    setFormat(String format)
    Sets the date-time format pattern, e.g.
    void
    setHourStep(int hourStep)
    Sets the interval between the items of the hours column, e.g.
    void
    Sets the internationalization settings.
    void
    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.
    void
    setInvalid(boolean invalid)
     
    void
    setManualValidation(boolean enabled)
     
    void
    Sets the latest allowed date-time.
    void
    Sets the earliest allowed date-time.
    void
    setMinuteStep(int minuteStep)
    Sets the interval between the items of the minutes column, e.g.
    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.
    void
    setOkButtonVisible(boolean okButtonVisible)
    Sets whether the OK button of the action bar is visible.
    void
    setOpened(boolean opened)
    Opens or closes the popup.
    void
    setSecondStep(int secondStep)
    Sets the interval between the items of the seconds column.
    void
    setShowWeekNumbers(boolean showWeekNumbers)
    Sets whether ISO-8601 week numbers are shown in the calendar.
    void
    Sets the time selector shown in the popup: sliding columns (the default) or an analog clock face.
    void
    protected void
    Validates the current value against min/max on the server.

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent

    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, 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, 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.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasHelper

    getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface com.vaadin.flow.component.HasLabel

    getLabel, setLabel

    Methods inherited from interface com.vaadin.flow.component.HasPlaceholder

    getPlaceholder, setPlaceholder

    Methods 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, setWidthFull

    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.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.HasValue

    clear, getOptionalValue

    Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

    isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
  • Field Details

    • DEFAULT_FORMAT

      public static final String 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

      public DateTimeComboPicker(String label)
      Creates a new picker with the given label.
      Parameters:
      label - the field label
    • DateTimeComboPicker

      public DateTimeComboPicker(String label, LocalDateTime initialValue)
      Creates a new picker with the given label and initial value.
      Parameters:
      label - the field label
      initialValue - the initial value, may be null
  • 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:
      hasValidValue in class com.vaadin.flow.component.AbstractSinglePropertyField<DateTimeComboPicker,LocalDateTime>
    • setValue

      public void setValue(LocalDateTime value)

      The value is truncated to seconds precision, matching what the component can represent and serialize.

      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimeComboPicker,LocalDateTime>,LocalDateTime>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<DateTimeComboPicker,LocalDateTime>
    • setFormat

      public void setFormat(String format)
      Sets the date-time format pattern, e.g. dd.MM.yyyy HH:mm:ss or M/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, or null to use the default ("dd.MM.yyyy HH:mm")
    • getFormat

      public String getFormat()
      Gets the date-time format pattern.
      Returns:
      the format pattern
    • setMin

      public void setMin(LocalDateTime min)
      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, or null for no limit
    • getMin

      public LocalDateTime getMin()
      Gets the earliest allowed date-time.
      Returns:
      the minimum value, or null if not set
    • setMax

      public void setMax(LocalDateTime max)
      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, or null for no limit
    • getMax

      public LocalDateTime getMax()
      Gets the latest allowed date-time.
      Returns:
      the maximum value, or null if 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 - true to open the popup on field interaction
    • isAutoOpen

      public boolean isAutoOpen()
      Gets whether the popup opens on field interaction.
      Returns:
      true if auto-open is enabled
    • setOpened

      public void setOpened(boolean opened)
      Opens or closes the popup.
      Parameters:
      opened - true to open, false to close
    • isOpened

      public boolean isOpened()
      Gets whether the popup is open.
      Returns:
      true if 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 - true to show the clear button
    • isClearButtonVisible

      public boolean isClearButtonVisible()
      Gets whether the clear button is visible.
      Returns:
      true if 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

      public void setDateDisabledFunction(String jsFunctionExpression)
      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 (where month is 0-based) and returns true to 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 null removes 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, or null to remove
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • setInitialPosition

      public void setInitialPosition(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. Defaults to the current date-time.
      Parameters:
      initialPosition - the initial position, or null to use the current date-time
    • getInitialPosition

      public LocalDateTime getInitialPosition()
      Gets the initial popup position.
      Returns:
      the initial position, or null if 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 - true to apply selections immediately
    • isAutoApply

      public boolean isAutoApply()
      Gets whether selections are applied immediately.
      Returns:
      true if 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 with addToActionBar(Component...).
      Parameters:
      okButtonVisible - false to hide the OK button
    • isOkButtonVisible

      public boolean isOkButtonVisible()
      Gets whether the OK button of the action bar is visible.
      Returns:
      true if 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 - false to hide the Cancel button
    • isCancelButtonVisible

      public boolean isCancelButtonVisible()
      Gets whether the Cancel button of the action bar is visible.
      Returns:
      true if 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 with removeFromActionBar(Component...).
      Parameters:
      components - the components to add
    • removeFromActionBar

      public void removeFromActionBar(com.vaadin.flow.component.Component... components)
      Removes components added with addToActionBar(Component...).
      Parameters:
      components - the components to remove
    • setTimeView

      public void setTimeView(TimeView timeView)
      Sets the time selector shown in the popup: sliding columns (the default) or an analog clock face.
      Parameters:
      timeView - the time view, not null
    • getTimeView

      public TimeView 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 is TimeView.CLOCK.
      Parameters:
      autoAdvance - true to advance automatically
    • isAutoAdvance

      public boolean isAutoAdvance()
      Gets whether the analog clock advances to the next view automatically.
      Returns:
      true if 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; 0 advances immediately. Only applies when the time view is TimeView.CLOCK and 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 with DateTimeComboPickerI18n.setDateTab(String) and DateTimeComboPickerI18n.setTimeTab(String).
      Parameters:
      mobileTabs - true to use the tabbed fullscreen layout
    • isMobileTabs

      public boolean isMobileTabs()
      Gets whether the fullscreen (mobile) popup uses the tabbed layout.
      Returns:
      true if 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 - true to show week numbers
    • isShowWeekNumbers

      public boolean isShowWeekNumbers()
      Gets whether week numbers are shown.
      Returns:
      true if week numbers are shown
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Specified by:
      setErrorMessage in interface com.vaadin.flow.component.HasValidation
    • getErrorMessage

      public String getErrorMessage()
      Specified by:
      getErrorMessage in interface com.vaadin.flow.component.HasValidation
    • setInvalid

      public void setInvalid(boolean invalid)
      Specified by:
      setInvalid in interface com.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:
      isInvalid in interface com.vaadin.flow.component.HasValidation
    • setManualValidation

      public void setManualValidation(boolean enabled)
      Specified by:
      setManualValidation in interface com.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. by Binder).

      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

      public void setI18n(DateTimeComboPickerI18n i18n)
      Sets the internationalization settings.
      Parameters:
      i18n - the i18n object, not null
    • getI18n

      public DateTimeComboPickerI18n 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 null if not set