Class FDateField

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<Date>,Date>
com.vaadin.flow.component.customfield.CustomField<Date>
com.vaadin.featurepack.ui.FDateField
All Implemented Interfaces:
Buffered, BufferedValidatable, Property<Date>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Field<Date>, Validatable, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, ClientConnector, FAbstractClientConnector, FSizeable, HasSizeable, FAbstractComponent, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<Date>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<Date>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<Date>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, 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<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>, Serializable

public class FDateField extends com.vaadin.flow.component.customfield.CustomField<Date> implements FAbstractComponent, Field<Date>, FieldEvents.FocusNotifier, FieldEvents.BlurNotifier, Validatable, HasSizeable

A date editor component that can be bound to any Property that is compatible with java.util.Date.

Since DateField implements FAbstractField and it implements the Buffered interface.

Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • FDateField

      public FDateField()
      Constructs an empty FDateField with no caption.
    • FDateField

      public FDateField(String caption)
      Constructs an empty FDateField with caption.
      Parameters:
      caption - the caption of the datefield.
    • FDateField

      public FDateField(String caption, Property dataSource)
      Constructs a new FDateField that's bound to the specified Property and has the given caption String.
      Parameters:
      caption - the caption String for the editor.
      dataSource - the Property to be edited with this editor.
    • FDateField

      public FDateField(Property dataSource) throws IllegalArgumentException
      Constructs a new FDateField that's bound to the specified Property and has no caption.
      Parameters:
      dataSource - the Property to be edited with this editor.
      Throws:
      IllegalArgumentException
    • FDateField

      public FDateField(String caption, Date value)
      Constructs a new FDateField with the given caption and initial text contents. The editor constructed this way will not be bound to a Property unless Property.Viewer.setPropertyDataSource(Property) is called to bind it.
      Parameters:
      caption - the caption String for the editor.
      value - the Date value.
  • Method Details

    • setLabelComponent

      public void setLabelComponent(com.vaadin.flow.component.Component labelComponent)
      Description copied from interface: FAbstractComponent
      Sets the component's label component. Flow components that support caption component usually overrides this.
      Specified by:
      setLabelComponent in interface FAbstractComponent
      Parameters:
      labelComponent - the new label component for the component.
    • onAttach

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

      protected Date generateModelValue()
      Specified by:
      generateModelValue in class com.vaadin.flow.component.customfield.CustomField<Date>
    • setPresentationValue

      protected void setPresentationValue(Date date)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<Date>
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • getType

      public Class<Date> getType()
      Description copied from interface: Property
      Returns the type of the Property. The methods getValue and setValue must be compatible with this type: one must be able to safely cast the value returned from getValue to the given type and pass any variable assignable to this type as an argument to setValue.
      Specified by:
      getType in interface Field<Date>
      Specified by:
      getType in interface Property<Date>
      Returns:
      type of the Property
    • validate

      public void validate() throws Validator.InvalidValueException
      Description copied from interface: Validatable

      Checks the validity of the validatable. If the validatable is valid this method should do nothing, and if it's not valid, it should throw Validator.InvalidValueException

      Specified by:
      validate in interface Validatable
      Throws:
      Validator.InvalidValueException - if the value is not valid
    • isValid

      public boolean isValid()
      Description copied from interface: Validatable

      Tests the current value of the object against all registered validators. The registered validators are iterated and for each the Validator.validate(Object) method is called. If any validator throws the Validator.InvalidValueException this method returns false.

      Specified by:
      isValid in interface Field<Date>
      Specified by:
      isValid in interface Validatable
      Returns:
      true if the registered validators concur that the value is valid, false otherwise
    • getValue

      public Date getValue()
      Description copied from interface: Property
      Gets the value stored in the Property. The returned object is compatible with the class returned by getType().
      Specified by:
      getValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>
      Specified by:
      getValue in interface Property<Date>
      Overrides:
      getValue in class com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<Date>,Date>
      Returns:
      the value stored in the Property
    • setValue

      public void setValue(Date value)
      Description copied from interface: Property
      Sets the value of the Property.

      Implementing this functionality is optional. If the functionality is missing, one should declare the Property to be in read-only mode and throw Property.ReadOnlyException in this function.

      Note : Since Vaadin 7.0, setting the value of a non-String property as a String is no longer supported.
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>
      Specified by:
      setValue in interface Property<Date>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<Date>,Date>
      Parameters:
      value - New value of the Property. This should be assignable to the type returned by getType
    • shouldHideErrors

      protected boolean shouldHideErrors()
      Returns true if the error indicator be hidden when painting the component even when there are errors. This is a mostly internal method, but can be overridden in subclasses e.g. if the error indicator should also be shown for empty fields in some cases.
      Returns:
      true to hide the error indicator, false to use the normal logic to show it when there are errors
    • setRangeStart

      public void setRangeStart(Date 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
      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
    • setRangeEnd

      public void setRangeEnd(Date 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.
      Parameters:
      endDate - - the allowed range's end date (inclusive, based on the current resolution)
    • getRangeStart

      public Date getRangeStart()
      Returns the precise rangeStart used.
    • getRangeEnd

      public Date getRangeEnd()
      Returns the precise rangeEnd used.
    • discard

      public void discard()
      Description copied from interface: Buffered
      Discards all changes since last commit. The object updates its value from the data source.
      Specified by:
      discard in interface Buffered
      Specified by:
      discard in interface Field<Date>
    • handleUnparsableDateString

      protected Date handleUnparsableDateString(String dateString) throws Converter.ConversionException
      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, a Converter.ConversionException is thrown, and the current value is not modified. This can be overridden to handle conversions, to return null (equivalent to empty input), to throw an exception or to fire an event.
      Parameters:
      dateString -
      Returns:
      parsed Date
      Throws:
      Converter.ConversionException - to keep the old value and indicate an error
    • getResolution

      public Resolution getResolution()
      Gets the resolution.
      Returns:
      int
    • setResolution

      public void setResolution(Resolution resolution)
      Sets the resolution of the DateField. The default resolution is Resolution.DAY since Vaadin 7.0.
      Parameters:
      resolution - the resolution to set.
    • 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
    • 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
    • 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:
    • isLenient

      public boolean isLenient()
      Returns whether date/time interpretation is to be lenient.
      Returns:
      true if the interpretation mode of this calendar is lenient; false otherwise.
      See Also:
    • 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

      public void setParseErrorMessage(String parsingErrorMessage)
      Sets the default error message used if the DateField cannot parse the text input by user to a Date field. Note that if the handleUnparsableDateString(String) method is overridden, the localized message from its exception is used.
      Parameters:
      parsingErrorMessage -
      See Also:
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
      Sets the time zone used by this date field. The time zone is used to convert the absolute time in a Date object to a logical time displayed in the selector and to convert the select time back to a Date object. If no time zone has been set, the current default time zone returned by TimeZone.getDefault() is used.
      Parameters:
      timeZone - the time zone to use for time calculations.
      See Also:
    • getTimeZone

      public TimeZone getTimeZone()
      Gets the time zone used by this field. The time zone is used to convert the absolute time in a Date object to a logical time displayed in the selector and to convert the select time back to a Date object. If null is returned, the current default time zone returned by TimeZone.getDefault() is used.
      Returns:
      the current time zone
    • getDateOutOfRangeMessage

      public String getDateOutOfRangeMessage()
      Returns current date-out-of-range error message.
      Returns:
      Current error message for dates out of range.
      Since:
      7.4
      See Also:
    • setLocale

      public void setLocale(Locale locale)
      Description copied from interface: FAbstractComponent
      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);
       
      Specified by:
      setLocale in interface FAbstractComponent
      Parameters:
      locale - the locale to become this component's locale.
    • setStep

      public void setStep(Duration step)
      Sets the step of the time picker. See DateTimePicker.setStep(Duration) for more information.
      Parameters:
      step - the step to set, not null and should divide a day or an hour evenly
      See Also:
      • DateTimePicker.setStep(Duration)
    • getStep

      public Duration getStep()
      Gets the step of the time picker.
      Returns:
      the step property from the picker, unit seconds
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<Date>,Date>,Date>
    • fireEvent

      protected void fireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent)
      Overrides:
      fireEvent in class com.vaadin.flow.component.Component