com.vaadin.ui.

Class AbstractDateField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>,​R extends Enum<R>>

    • Constructor Detail

      • AbstractDateField

        public AbstractDateField​(R resolution)

        Constructs an empty AbstractDateField with no caption and specified resolution.

        Parameters:

        resolution - initial resolution for the field, not null

      • AbstractDateField

        public AbstractDateField​(String caption,
                                 R resolution)

        Constructs an empty AbstractDateField with caption.

        Parameters:

        caption - the caption of the datefield

        resolution - initial resolution for the field, not null

      • AbstractDateField

        public AbstractDateField​(String caption,
                                 T value,
                                 R resolution)

        Constructs a new AbstractDateField with the given caption and initial text contents.

        Parameters:

        caption - the caption String for the editor.

        value - the date/time value.

        resolution - initial resolution for the field, not null

    • Method Detail

      • beforeClientResponse

        public void beforeClientResponse​(boolean initial)

        Description copied from interface: ClientConnector

        Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.

        Specified by:

        beforeClientResponse in interface ClientConnector

        Overrides:

        beforeClientResponse in class AbstractComponent

        Parameters:

        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.

      • reconstructDateFromFields

        protected T reconstructDateFromFields​(Map<String,​Integer> resolutions,
                                              T oldDate)

        Construct a date object from the individual field values received from the client.

        Parameters:

        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

        Returns:

        the date object built from the specified resolutions

        Since:

        8.2

      • setRangeStart

        public void setRangeStart​(T startDate)

        Sets the start range for this component. If the value is set before this date (taking the resolution into account), the component will not validate. If 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.

        Parameters:

        startDate - - the allowed range's start date

      • setDateOutOfRangeMessage

        public void setDateOutOfRangeMessage​(String dateOutOfRangeMessage)

        Sets the current error message if the range validation fails.

        Parameters:

        dateOutOfRangeMessage - - Localizable message which is shown when value (the date) is set outside allowed range

      • getDateOutOfRangeMessage

        public String getDateOutOfRangeMessage()

        Returns current date-out-of-range error message.

        Returns:

        Current error message for dates out of range.

        See Also:

        setDateOutOfRangeMessage(String)

      • getResolution

        public R getResolution()

        Gets the resolution.

        Returns:

        the date/time field resolution

      • setResolution

        public void setResolution​(R resolution)

        Sets the resolution of the DateField. The default resolution is DateResolution.DAY since Vaadin 7.0.

        Parameters:

        resolution - the resolution to set, not null

      • setRangeEnd

        public void setRangeEnd​(T endDate)

        Sets the end range for this component. If the value is set after this date (taking the resolution into account), the component will not validate. If 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.

        Parameters:

        endDate - the allowed range's end date (inclusive, based on the current resolution)

      • getRangeStart

        public T getRangeStart()

        Returns the precise rangeStart used.

        Returns:

        the precise rangeStart used, may be null.

      • toType

        protected abstract T toType​(TemporalAccessor temporalAccessor)

        Converts a temporal value into field-specific data type.

        Parameters:

        temporalAccessor - - source value

        Returns:

        conversion result.

        Since:

        8.4

      • afterDate

        protected boolean afterDate​(T value,
                                    T base)

        Checks if value is after base or not.

        Parameters:

        value - temporal value

        base - temporal value to compare to

        Returns:

        true if value is after base, false otherwise

      • getRangeEnd

        public T getRangeEnd()

        Returns the precise rangeEnd used.

        Returns:

        the precise rangeEnd used, may be null.

      • setDateFormat

        public void setDateFormat​(String dateFormat)

        Sets formatting used by some component implementations. See 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.

        Parameters:

        dateFormat - the dateFormat to set, can be null

        See Also:

        AbstractComponent.setLocale(Locale)

      • getDateFormat

        public String getDateFormat()

        Returns a format string used to format date value on client side or null if default formatting from Component.getLocale() is used.

        Returns:

        the dateFormat

      • setZoneId

        public void setZoneId​(ZoneId zoneId)

        Sets the ZoneId, which is used when z is included inside the setDateFormat(String) .

        Parameters:

        zoneId - the zone id

        Since:

        8.2

      • setDaylightSavingTimeRange

        public 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. 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 1980, and endYear is set to 20 years into the future from the current date.

        Parameters:

        startYear - the start year of DST transitions

        endYear - the end year of DST transitions

        Since:

        8.11

      • setLocale

        public void setLocale​(Locale locale)

        Description copied from class: AbstractComponent

        Sets the locale of this component.

         // 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);
         

        Overrides:

        setLocale in class AbstractComponent

        Parameters:

        locale - the locale to become this component's locale.

      • setLenient

        public void setLenient​(boolean lenient)

        Specifies whether or not date/time interpretation in component is to be lenient.

        Parameters:

        lenient - true if the lenient mode is to be turned on; false if it is to be turned off.

        See Also:

        Calendar.setLenient(boolean), isLenient()

      • isLenient

        public boolean isLenient()

        Returns whether date/time interpretation is lenient.

        Returns:

        true if the interpretation mode of this calendar is lenient; false otherwise.

        See Also:

        setLenient(boolean)

      • getValue

        public T getValue()

        Description copied from interface: HasValue

        Returns the current value of this object.

        Implementation note: the implementing class should document whether null values may be returned or not.

        Specified by:

        getValue in interface HasValue<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>

        Returns:

        the current value

      • getDefaultValue

        public T getDefaultValue()

        Returns the current default value.

        Returns:

        the default value

        Since:

        8.1.2

        See Also:

        setDefaultValue(Temporal)

      • setDefaultValue

        public void setDefaultValue​(T defaultValue)

        Sets the default value for the field. The default value is the starting point for the date field when nothing has been selected yet. If no default value is set, current date/time is used.

        Parameters:

        defaultValue - the default value, may be null

        Since:

        8.1.2

      • adjustToResolution

        protected abstract T adjustToResolution​(T date,
                                                R resolution)

        Adjusts the given date to the given resolution. Any values that are more specific than the given resolution are truncated to their default values.

        Parameters:

        date - the date to adjust, can be null

        resolution - the resolution to be used in the adjustment, can be null

        Returns:

        an adjusted date that matches the given resolution, or null if the given date, resolution, or both were null

      • isShowISOWeekNumbers

        public boolean isShowISOWeekNumbers()

        Checks whether ISO 8601 week numbers are shown in the date selector.

        Returns:

        true if week numbers are shown, false otherwise.

      • setShowISOWeekNumbers

        public void setShowISOWeekNumbers​(boolean showWeekNumbers)

        Sets the visibility of ISO 8601 week numbers in the date selector. ISO 8601 defines that a week always starts with a Monday so the week numbers are only shown if this is the case.

        Parameters:

        showWeekNumbers - true if week numbers should be shown, false otherwise.

      • getParseErrorMessage

        public String getParseErrorMessage()

        Return the error message that is shown if the user inputted value can't be parsed into a Date object. If 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.

        Returns:

        the error message that the DateField uses when it can't parse the textual input from user to a Date object

        See Also:

        setParseErrorMessage(String)

      • readDesign

        public void readDesign​(org.jsoup.nodes.Element design,
                               DesignContext designContext)

        Description copied from interface: Component

        Reads the component state from the given design.

        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.

        Specified by:

        readDesign in interface Component

        Overrides:

        readDesign in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>

        Parameters:

        design - The element to obtain the state from

        designContext - The DesignContext instance used for parsing the design

      • formatDate

        protected abstract String formatDate​(T value)

        Formats date according to the components locale.

        Parameters:

        value - the date or null

        Returns:

        textual representation of the date or empty string for null

        Since:

        8.1.1

      • writeDesign

        public void writeDesign​(org.jsoup.nodes.Element design,
                                DesignContext designContext)

        Description copied from interface: Component

        Writes the component state to the given design.

        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.

        Specified by:

        writeDesign in interface Component

        Overrides:

        writeDesign in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>

        Parameters:

        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 design

      • handleUnparsableDateString

        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. By default, an error result is returned whose error message is 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.

        Parameters:

        dateString - date string to handle

        Returns:

        result that contains parsed Date as a value or an error

      • doSetValue

        protected void doSetValue​(T value)

        Description copied from class: AbstractField

        Sets the value of this field. May do sanitization or throw IllegalArgumentException if the value is invalid. Typically saves the value to shared state.

        Specified by:

        doSetValue in class AbstractField<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>

        Parameters:

        value - the new value of the field

      • getDatePart

        protected abstract int getDatePart​(T date,
                                           R resolution)

        Returns a date integer value part for the given date for the given resolution.

        Parameters:

        date - the given date, can be null

        resolution - the resolution to extract a value from the date by, not null

        Returns:

        the integer value part of the date by the given resolution

      • buildDate

        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.

        This is the opposite to getDatePart(Temporal, Enum).

        Parameters:

        resolutionValues - date values to construct a date

        Returns:

        date built from the given map of date values

      • getRangeValidator

        protected abstract RangeValidator<T> getRangeValidator()

        Returns a custom date range validator which is applicable for the type T.

        Returns:

        the date range validator

      • convertFromDate

        protected abstract T convertFromDate​(Date date)

        Converts Date to date type T.

        Parameters:

        date - a date to convert

        Returns:

        object of type T representing the date

      • convertToDate

        protected abstract Date convertToDate​(T date)

        Converts the object of type T to Date.

        This is the opposite to convertFromDate(Date).

        Parameters:

        date - the date of type T

        Returns:

        converted date of type Date

      • getDefaultValidator

        public Validator<T> getDefaultValidator()

        Description copied from interface: HasValue

        Returns a validator that checks the internal state of the HasValue. This should be overridden for components with internal value conversion or validation, e.g. when the user is providing a string that has to be parsed into a date. An invalid input from user will be exposed to a Binder and can be seen as a validation failure.

        Specified by:

        getDefaultValidator in interface HasValue<T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>>

        Returns:

        internal state validator

        See Also:

        Binder.validate()

      • setDateStyle

        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");

        Parameters:

        date - which date cell to modify, not null

        styleName - the custom style name(s) for given date, null to clear custom style name(s)

        Since:

        8.3

      • getDateStyle

        public String getDateStyle​(LocalDate date)

        Returns the custom style name that corresponds with the given date's calendar cell.

        Parameters:

        date - which date cell's custom style name(s) to return, not null

        Returns:

        the corresponding style name(s), if any, null otherwise

        Since:

        8.3

        See Also:

        setDateStyle(LocalDate, String)

      • getDateStyles

        public Map<LocalDate,​String> getDateStyles()

        Returns a map from dates to custom style names in each date's calendar cell.

        Returns:

        unmodifiable map from dates to custom style names in each date's calendar cell

        Since:

        8.3

        See Also:

        setDateStyle(LocalDate, String)

      • setAssistiveLabel

        public void setAssistiveLabel​(AbstractDateFieldState.AccessibleElement element,
                                      String label)

        Sets the assistive label for a calendar navigation element. This sets the aria-label attribute for the element which is used by screen reading software.

        Parameters:

        element - the element for which to set the label. Not null.

        label - the assistive label to set

        Since:

        8.4

      • getAssistiveLabel

        public void getAssistiveLabel​(AbstractDateFieldState.AccessibleElement element)

        Gets the assistive label of a calendar navigation element.

        Parameters:

        element - the element of which to get the assistive label

        Since:

        8.4

      • setPreventInvalidInput

        public void setPreventInvalidInput​(boolean preventInvalidInput)

        Control whether value change event is emitted when user input value does not meet the integrated range validator.

        Parameters:

        preventInvalidInput - Set to false to disable the value change event.

        Since:

        8.13

      • isPreventInvalidInput

        public boolean isPreventInvalidInput()

        Check whether value change is emitted when user input value does not meet integrated range validator. The default is false.

        Returns:

        a Boolean value

        Since:

        8.13