@JavaScript(value="frontend://timepickerConnector.js") @JsModule(value="./timepickerConnector.js") public class TimePicker extends GeneratedVaadinTimePicker<TimePicker,LocalTime> implements HasSize, HasValidation, HasEnabled, HasHelper, HasLabel, HasValidator<LocalTime>, HasClientValidation
vaadin-time-picker
web component.GeneratedVaadinTimePicker.InvalidChangeEvent<R extends GeneratedVaadinTimePicker<R,?>>
AbstractField.ComponentValueChangeEvent<C extends Component,V>
HasClientValidation.ClientValidatedEvent
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
Constructor and Description |
---|
TimePicker()
Default constructor.
|
TimePicker(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<TimePicker,LocalTime>> listener)
Convenience constructor to create a time picker with a
ValueChangeListener . |
TimePicker(LocalTime time)
Convenience constructor to create a time picker with a pre-selected time.
|
TimePicker(String label)
Convenience constructor to create a time picker with a label.
|
TimePicker(String label,
LocalTime time)
Convenience constructor to create a time picker with a pre-selected time
and a label.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addInvalidChangeListener(ComponentEventListener<GeneratedVaadinTimePicker.InvalidChangeEvent<TimePicker>> listener)
Adds a listener for
invalid-changed events fired by the
webcomponent. |
Registration |
addValidationStatusChangeListener(ValidationStatusChangeListener<LocalTime> listener)
Enables the implementing components to notify changes in their validation
status to the observers.
|
static <V extends Comparable<V>> |
checkGreaterThanMax(V value,
V maxValue) |
static <V> ValidationResult |
checkRequired(boolean required,
V value,
V emptyValue) |
static <V extends Comparable<V>> |
checkSmallerThanMin(V value,
V minValue) |
Validator<LocalTime> |
getDefaultValidator()
Returns a validator that checks the state of the Value.
|
String |
getErrorMessage()
Gets the current error message from the time picker.
|
String |
getLabel()
Gets the label of the time picker.
|
Locale |
getLocale()
Gets the Locale for this time picker.
|
String |
getMax()
Deprecated.
use
getMaxTime() instead. |
LocalTime |
getMaxTime()
Gets the maximum time in the time picker.
|
String |
getMin()
Deprecated.
use
getMinTime() instead. |
LocalTime |
getMinTime()
Gets the minimum time in the time picker.
|
String |
getPlaceholder()
Gets the placeholder of the time picker.
|
Duration |
getStep()
Gets the step of the time picker.
|
static Stream<Locale> |
getSupportedAvailableLocales()
Returns a stream of all the available locales that are supported by the
time picker component.
|
boolean |
isAutoOpen()
Gets whether dropdown will open automatically or not.
|
boolean |
isClearButtonVisible()
Gets whether this time picker displays a clear button when it has value.
|
protected boolean |
isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
|
protected boolean |
isInputValuePresent()
Returns whether the input element has a value or not.
|
boolean |
isInvalid()
Gets the validity of the time picker output.
|
boolean |
isRequired()
Determines whether the time picker is marked as input required.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
setAutoOpen(boolean autoOpen)
Enables or disables the dropdown opening automatically.
|
void |
setClearButtonVisible(boolean clearButtonVisible)
Sets displaying a clear button in the time picker when it has value.
|
void |
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
|
void |
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
|
void |
setLabel(String label)
Sets the label for the time picker.
|
void |
setLocale(Locale locale)
Set the Locale for the Time Picker.
|
void |
setMax(String max)
Deprecated.
use
setMaxTime(LocalTime) instead. |
void |
setMaxTime(LocalTime max)
Sets the maximum time in the time picker.
|
void |
setMin(String min)
Deprecated.
use
setMinTime(LocalTime) instead. |
void |
setMinTime(LocalTime min)
Sets the minimum time in the time picker.
|
void |
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
|
void |
setRequired(boolean required)
Description copied from corresponding location in WebComponent:
|
void |
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
|
void |
setStep(Duration step)
Sets the
step property of the time picker using duration. |
void |
setValue(LocalTime value)
Sets the selected time value of the component.
|
protected void |
validate()
Performs server-side validation of the current value.
|
checkValidity, getErrorMessageString, getI18nJsonObject, getLabelString, getMaxString, getMinString, getNameString, getPatternString, getPlaceholderString, getStepDouble, isAutofocusBoolean, isClearButtonVisibleBoolean, isDisabledBoolean, isInvalidBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, setAutofocus, setDisabled, setI18n, setName, setPattern, setPreventInvalidInput, setReadonly, setStep
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEquals
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
isEnabled, setEnabled
getHelperComponent, getHelperText, setHelperComponent, setHelperText
getElement
addClientValidatedEventListener
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isReadOnly, isRequiredIndicatorVisible, setReadOnly
clear, getOptionalValue
addAttachListener
addDetachListener
public TimePicker()
public TimePicker(LocalTime time)
time
- the pre-selected time in the pickerpublic TimePicker(String label)
label
- the label describing the time pickersetLabel(String)
public TimePicker(String label, LocalTime time)
label
- the label describing the time pickertime
- the pre-selected time in the pickerpublic TimePicker(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<TimePicker,LocalTime>> listener)
ValueChangeListener
.listener
- the listener to receive value change eventsAbstractField.addValueChangeListener(HasValue.ValueChangeListener)
public void setLabel(String label)
setLabel
in interface HasLabel
setLabel
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
label
- value for the label
property in the time pickerpublic void setValue(LocalTime value)
The value will be truncated to millisecond precision, as that is the
maximum that the time picker supports. This means that
AbstractField.getValue()
might return a different value than what was passed
in.
setValue
in interface HasValue<AbstractField.ComponentValueChangeEvent<TimePicker,LocalTime>,LocalTime>
setValue
in class AbstractField<TimePicker,LocalTime>
value
- the LocalTime instance representing the selected time, or nullpublic String getLabel()
public void setErrorMessage(String errorMessage)
GeneratedVaadinTimePicker
Description copied from corresponding location in WebComponent:
The error message to display when the input is invalid.
setErrorMessage
in interface HasValidation
setErrorMessage
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
errorMessage
- the String value to setpublic String getErrorMessage()
getErrorMessage
in interface HasValidation
public void setInvalid(boolean invalid)
GeneratedVaadinTimePicker
Description copied from corresponding location in WebComponent:
Set to true if the value is invalid.
setInvalid
in interface HasValidation
setInvalid
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
invalid
- the boolean value to setpublic boolean isInvalid()
return true, if the value is invalid.
isInvalid
in interface HasValidation
validity
property from the time pickerpublic Validator<LocalTime> getDefaultValidator()
HasValidator
Binder
and
can be seen as a validation failure.getDefaultValidator
in interface HasValidator<LocalTime>
public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<LocalTime> listener)
HasValidator
Note: This method can be overridden by the implementing
classes e.g. components, to enable the associated Binder.Binding
instance subscribing for their validation change events and revalidate
itself.
This method primarily designed for notifying the Binding about the
validation status changes of a bound component at the client-side.
WebComponents such as <vaadin-date-picker>
or any
other component that accept a formatted text as input should be able to
communicate their invalid status to their server-side instance, and a
bound server-side component instance must notify its binding about this
validation status change as well. When the binding instance revalidates,
a chain of validators and convertors get executed one of which is the
default validator provided by HasValidator.getDefaultValidator()
.
Thus, In order for the binding to be able to show/clear errors for its
associated bound field, it is important that implementing components take
that validation status into account while implementing any validator and
converter including HasValidator.getDefaultValidator()
. Here is
an example:
@Tag("date-picker-demo")
public class DatePickerDemo implements HasValidator<LocalDate> {
// Each web component has a way to communicate its validation status
// to its server-side component instance. The following clientSideValid
// state is introduced here just for the sake of simplicity of this code
// snippet:
boolean clientSideValid = true;
/**
* Note how clientSideValid
engaged in the definition
* of this method. It is important to reflect this status either
* in the returning validation result of this method or any other
* validation that is associated with this component.
*/
@Override
public Validator getDefaultValidator() {
return (value, valueContext) -> clientSideValid ? ValidationResult.ok()
: ValidationResult.error("Invalid date format");
}
private final Collection<ValidationStatusChangeListener<LocalDate>>
validationStatusListeners = new ArrayList<>();
/**
* This enables the binding to subscribe for the validation status
* change events that are fired by this component and revalidate
* itself respectively.
*/
@Override
public Registration addValidationStatusChangeListener(
ValidationStatusChangeListener<LocalDate> listener) {
validationStatusListeners.add(listener);
return () -> validationStatusListeners.remove(listener);
}
private void fireValidationStatusChangeEvent(
boolean newValidationStatus) {
if (this.clientSideValid != newValidationStatus) {
this.clientSideValid = newValidationStatus;
var event = new ValidationStatusChangeEvent<>(this,
newValidationStatus);
validationStatusListeners.forEach(
listener -> listener.validationStatusChanged(event));
}
}
}
addValidationStatusChangeListener
in interface HasValidator<LocalTime>
Binder.BindingBuilderImpl.bind(ValueProvider,
Setter)
public static <V extends Comparable<V>> ValidationResult checkGreaterThanMax(V value, V maxValue)
public static <V extends Comparable<V>> ValidationResult checkSmallerThanMin(V value, V minValue)
public static <V> ValidationResult checkRequired(boolean required, V value, V emptyValue)
@Synchronize(property="_hasInputValue", value="has-input-value-changed") protected boolean isInputValuePresent()
true
if the input element's value is populated,
false
otherwisepublic void setPlaceholder(String placeholder)
GeneratedVaadinTimePicker
Description copied from corresponding location in WebComponent:
A placeholder string in addition to the label.
setPlaceholder
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
placeholder
- the String value to setpublic String getPlaceholder()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
placeholder
property of the time pickerpublic void setRequired(boolean required)
GeneratedVaadinTimePicker
Description copied from corresponding location in WebComponent:
Set to true to mark the input as required.
setRequired
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
required
- the boolean value to setpublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
HasValue
If set visible, it is visually indicated in the user interface.
The method is intended to be used with Binder
which does
server-side validation. In case HTML element has its own (client-side)
validation it should be disabled when
setRequiredIndicatorVisible(true)
is called and re-enabled
back on setRequiredIndicatorVisible(false)
. It's
responsibility of each component implementation to follow the contract so
that the method call doesn't do anything else than show/hide the
"required" indication. Usually components provide their own
setRequired
method which should be called in case the
client-side validation is required.
setRequiredIndicatorVisible
in interface HasValue<AbstractField.ComponentValueChangeEvent<TimePicker,LocalTime>,LocalTime>
setRequiredIndicatorVisible
in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<TimePicker,LocalTime>,LocalTime>
requiredIndicatorVisible
- true
to make the required indicator visible,
false
if notpublic boolean isRequired()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
true
if the input is required, false
otherwisepublic void setStep(Duration step)
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 in hh: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.
step
- the step to set, not null
and should divide a day or
an hour evenlypublic Duration getStep()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
step
property from the picker, unit secondspublic Registration addInvalidChangeListener(ComponentEventListener<GeneratedVaadinTimePicker.InvalidChangeEvent<TimePicker>> listener)
GeneratedVaadinTimePicker
invalid-changed
events fired by the
webcomponent.addInvalidChangeListener
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
listener
- the listenerRegistration
for removing the event listenerprotected void validate()
validate
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
public void setLocale(Locale locale)
By default, the locale is null
until the component is attached to
an UI, and then locale is set to UI.getLocale()
, unless a locale
has been explicitly set before that.
The time formatting is done in the browser using the Date.toLocaleTimeString() function.
If for some reason the browser doesn't support the given locale, the en-US locale is used.
NOTE: only the language + country/region codes are used. This
means that the script and variant information is not used and supported.
NOTE: timezone related data is not supported. NOTE: changing
the locale does not cause a new
HasValue.ValueChangeEvent
to be
fired.
locale
- the locale set to the time picker, cannot be [@code null}public Locale getLocale()
By default, the locale is null
until the component is attached to
an UI, and then locale is set to UI.getLocale()
, unless
setLocale(Locale)
has been explicitly called before that.
@Deprecated public void setMin(String min)
setMinTime(LocalTime)
instead.setMin
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
min
- the minimum time that is allowed to be selected, or
null
to remove any minimum constraintspublic void setMinTime(LocalTime min)
min
- the minimum time that is allowed to be selected, or
null
to remove any minimum constraints@Deprecated public String getMin()
getMinTime()
instead.null
if there's no minimumpublic LocalTime getMinTime()
null
if there's no minimum@Deprecated public void setMax(String max)
setMaxTime(LocalTime)
instead.setMax
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
max
- the maximum time that is allowed to be selected, or
null
to remove any maximum constraintspublic void setMaxTime(LocalTime max)
max
- the maximum time that is allowed to be selected, or
null
to remove any maximum constraints@Deprecated public String getMax()
getMaxTime()
instead.null
if there's no maximumpublic LocalTime getMaxTime()
null
if there's no maximumpublic void setClearButtonVisible(boolean clearButtonVisible)
The clear button is an icon, which can be clicked to set the time picker
value to null
.
setClearButtonVisible
in class GeneratedVaadinTimePicker<TimePicker,LocalTime>
clearButtonVisible
- true
to display the clear button, false
to
hide itpublic boolean isClearButtonVisible()
true
if this time picker displays a clear button,
false
otherwisesetClearButtonVisible(boolean)
public void setAutoOpen(boolean autoOpen)
false
the dropdown is only opened when clicking the toggle button or pressing
Up or Down arrow keys.autoOpen
- false
to prevent the dropdown from opening
automaticallypublic boolean isAutoOpen()
false
otherwisepublic static Stream<Locale> getSupportedAvailableLocales()
This is a shorthand for Locale.getAvailableLocales()
where all
locales without the Locale.getLanguage()
have been filtered out,
as the browser cannot localize the time for those.
setLocale(Locale)
,
Locale.getAvailableLocales()
,
Locale.getLanguage()
protected boolean isEnforcedFieldValidationEnabled()
Exposed with protected visibility to support mocking
The method requires the VaadinSession
instance to obtain the
application configuration properties, otherwise, the feature is
considered disabled.
true
if enabled, false
otherwise.Copyright © 2025. All rights reserved.