Class AbstractField<T>

    • Constructor Detail

      • AbstractField

        public AbstractField()
        Deprecated.
    • Method Detail

      • shouldHideErrors

        protected boolean shouldHideErrors()
        Deprecated.
        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
      • getType

        public abstract Class<? extends T> getType()
        Deprecated.
        Returns the type of the Field. 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 Property<T>
        Returns:
        the type of the Field
      • discard

        public void discard()
                     throws Buffered.SourceException
        Deprecated.
        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
        Throws:
        Buffered.SourceException - if the operation fails because of an exception is thrown by the data source. The cause is included in the exception.
      • isModified

        public boolean isModified()
        Deprecated.
        Description copied from interface: Buffered
        Tests if the value stored in the object has been modified since it was last updated from the data source.
        Specified by:
        isModified in interface Buffered
        Returns:
        true if the value in the object has been modified since the last data source update, false if not.
      • setBuffered

        public void setBuffered​(boolean buffered)
        Deprecated.
        Sets the buffered mode of this Field.

        When the field is in buffered mode, changes will not be committed to the property data source until commit() is called.

        Setting buffered mode from true to false will commit any pending changes.

        Specified by:
        setBuffered in interface Buffered
        Parameters:
        buffered - true if buffered mode should be turned on, false otherwise
        Since:
        7.0.0
      • isBuffered

        public boolean isBuffered()
        Deprecated.
        Checks the buffered mode of this Field.
        Specified by:
        isBuffered in interface Buffered
        Returns:
        true if buffered mode is on, false otherwise
      • getValue

        public T getValue()
        Deprecated.
        Gets the current value of the field.

        This is the visible, modified and possible invalid value the user have entered to the field.

        Note that the object returned is compatible with getType(). For example, if the type is String, this returns Strings even when the underlying datasource is of some other type. In order to access the converted value, use getConvertedValue() and to access the value of the property data source, use Property.getValue() for the property data source.

        Since Vaadin 7.0, no implicit conversions between other data types and String are performed, but a converter is used if set.

        Specified by:
        getValue in interface Property<T>
        Returns:
        the current value of the field.
      • getPropertyDataSource

        public Property getPropertyDataSource()
        Deprecated.
        Gets the current data source of the field, if any.
        Specified by:
        getPropertyDataSource in interface Property.Viewer
        Returns:
        the current data source as a Property, or null if none defined.
      • setPropertyDataSource

        public void setPropertyDataSource​(Property newDataSource)
        Deprecated.

        Sets the specified Property as the data source for the field. All uncommitted changes are replaced with a value from the new data source.

        If the datasource has any validators, the same validators are added to the field. Because the default behavior of the field is to allow invalid values, but not to allow committing them, this only adds visual error messages to fields and do not allow committing them as long as the value is invalid. After the value is valid, the error message is not shown and the commit can be done normally.

        If the data source implements Property.ValueChangeNotifier and/or Property.ReadOnlyStatusChangeNotifier, the field registers itself as a listener and updates itself according to the events it receives. To avoid memory leaks caused by references to a field no longer in use, the listener registrations are removed on detach and re-added on attach.

        Note: before 6.5 we actually called discard() method in the beginning of the method. This was removed to simplify implementation, avoid excess calls to backing property and to avoid odd value change events that were previously fired (developer expects 0-1 value change events if this method is called). Some complex field implementations might now need to override this method to do housekeeping similar to discard().

        Specified by:
        setPropertyDataSource in interface Property.Viewer
        Parameters:
        newDataSource - the new data source Property.
      • setConverter

        public void setConverter​(Class<?> datamodelType)
        Deprecated.
        Retrieves a converter for the field from the converter factory defined for the application. Clears the converter if no application reference is available or if the factory returns null.
        Parameters:
        datamodelType - The type of the data model that we want to be able to convert from
      • getModelType

        protected Class<?> getModelType()
        Deprecated.
        Retrieves the type of the currently used data model. If the field has no data source then the model type of the converter is used.
        Returns:
        The type of the currently used data model or null if no data source or converter is set.
        Since:
        7.1
      • getConversionError

        protected String getConversionError​(Class<?> dataSourceType,
                                            Converter.ConversionException e)
        Deprecated.
        Returns the conversion error with {0} replaced by the data source type and {1} replaced by the exception (localized) message.
        Parameters:
        dataSourceType - the type of the data source
        e - a conversion exception which can provide additional information
        Returns:
        The value conversion error string with parameters replaced.
        Since:
        7.1
      • getConvertedValue

        public Object getConvertedValue()
        Deprecated.
        Returns the current value (as returned by getValue()) converted to the data source type.

        This returns the same as getValue() if no converter has been set. The value is not necessarily the same as the data source value e.g. if the field is in buffered mode and has been modified.

        Returns:
        The converted value that is compatible with the data source type
      • setConvertedValue

        public void setConvertedValue​(Object value)
        Deprecated.
        Sets the value of the field using a value of the data source type. The value given is converted to the field type and then assigned to the field. This will update the property data source in the same way as when setValue(Object) is called.
        Parameters:
        value - The value to set. Must be the same type as the data source.
      • addValidator

        public void addValidator​(Validator validator)
        Deprecated.
        Adds a new validator for the field's value. All validators added to a field are checked each time the its value changes.
        Specified by:
        addValidator in interface Validatable
        Parameters:
        validator - the new validator to be added.
      • getValidators

        public Collection<Validator> getValidators()
        Deprecated.
        Gets the validators of the field.
        Specified by:
        getValidators in interface Validatable
        Returns:
        An unmodifiable collection that holds all validators for the field.
      • removeValidator

        public void removeValidator​(Validator validator)
        Deprecated.
        Removes the validator from the field.
        Specified by:
        removeValidator in interface Validatable
        Parameters:
        validator - the validator to remove.
      • removeAllValidators

        public void removeAllValidators()
        Deprecated.
        Removes all validators from the field.
        Specified by:
        removeAllValidators in interface Validatable
      • isValid

        public boolean isValid()
        Deprecated.
        Tests the current value against registered validators if the field is not empty. If the field is empty it is considered valid if it is not required and invalid otherwise. Validators are never checked for empty fields. In most cases, validate() should be used instead of isValid() to also get the error message.
        Specified by:
        isValid in interface Validatable
        Returns:
        true if all registered validators claim that the current value is valid or if the field is empty and not required, false otherwise.
      • validate

        protected void validate​(T fieldValue)
                         throws Validator.InvalidValueException
        Deprecated.
        Validates that the given value pass the validators for the field.

        This method does not check the requiredness of the field.

        Parameters:
        fieldValue - The value to check
        Throws:
        Validator.InvalidValueException - if one or several validators fail
      • isInvalidAllowed

        public boolean isInvalidAllowed()
        Deprecated.
        Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately.
        Specified by:
        isInvalidAllowed in interface Validatable
        Returns:
        true if invalid values are allowed.
        See Also:
        Validatable.isInvalidAllowed()
      • setInvalidAllowed

        public void setInvalidAllowed​(boolean invalidAllowed)
                               throws UnsupportedOperationException
        Deprecated.
        Fields allow invalid values by default. In most cases this is wanted, because the field otherwise visually forget the user input immediately.

        In common setting where the user wants to assure the correctness of the datasource, but allow temporarily invalid contents in the field, the user should add the validators to datasource, that should not allow invalid values. The validators are automatically copied to the field when the datasource is set.

        Specified by:
        setInvalidAllowed in interface Validatable
        Throws:
        UnsupportedOperationException - if the setInvalidAllowed is not supported.
        See Also:
        Validatable.setInvalidAllowed(boolean)
      • fireValueChange

        protected void fireValueChange​(boolean repaintIsNotNeeded)
        Deprecated.
        Emits the value change event. The value contained in the field is validated before the event is created.
      • fireReadOnlyStatusChange

        protected void fireReadOnlyStatusChange()
        Deprecated.
        Emits the read-only status change event. The value contained in the field is validated before the event is created.
      • valueChange

        public void valueChange​(Property.ValueChangeEvent event)
        Deprecated.
        This method listens to data source value changes and passes the changes forwards. Changes are not forwarded to the listeners of the field during internal operations of the field to avoid duplicate notifications.
        Specified by:
        valueChange in interface Property.ValueChangeListener
        Parameters:
        event - the value change event telling the data source contents have changed.
      • getInternalValue

        protected T getInternalValue()
        Deprecated.
        Returns the internal field value, which might not match the data source value e.g. if the field has been modified and is not in write-through mode. This method can be overridden by subclasses together with setInternalValue(Object) to compute internal field value at runtime. When doing so, typically also isModified() needs to be overridden and care should be taken in the management of the empty state and buffering support.
        Returns:
        internal field value
      • setInternalValue

        protected void setInternalValue​(T newValue)
        Deprecated.
        Sets the internal field value. This is purely used by AbstractField to change the internal Field value. It does not trigger valuechange events. It can be overridden by the inheriting classes to update all dependent variables. Subclasses can also override getInternalValue() if necessary.
        Parameters:
        newValue - the new value to be set.
      • isRequired

        public boolean isRequired()
        Deprecated.
        Description copied from interface: Field
        Is this field required. Required fields must filled by the user.
        Specified by:
        isRequired in interface Field<T>
        Returns:
        true if the field is required,otherwise false.
      • setRequired

        public void setRequired​(boolean required)
        Deprecated.
        Description copied from interface: Field
        Sets the field required. Required fields must filled by the user.
        Specified by:
        setRequired in interface Field<T>
        Parameters:
        required - Is the field required.
      • setRequiredError

        public void setRequiredError​(String requiredMessage)
        Deprecated.
        Set the error that is show if this field is required, but empty. When setting requiredMessage to be "" or null, no error pop-up or exclamation mark is shown for a empty required field. This faults to "". Even in those cases isValid() returns false for empty required fields.
        Specified by:
        setRequiredError in interface Field<T>
        Parameters:
        requiredMessage - Message to be shown when this field is required, but empty.
      • getRequiredError

        public String getRequiredError()
        Deprecated.
        Description copied from interface: Field
        Gets the error message that is to be displayed if a required field is empty.
        Specified by:
        getRequiredError in interface Field<T>
        Returns:
        Error message.
      • getConversionError

        public String getConversionError()
        Deprecated.
        Gets the error that is shown if the field value cannot be converted to the data source type.
        Returns:
        The error that is shown if conversion of the field value fails
      • setConversionError

        public void setConversionError​(String valueConversionError)
        Deprecated.
        Sets the error that is shown if the field value cannot be converted to the data source type. If {0} is present in the message, it will be replaced by the simple name of the data source type. If {1} is present in the message, it will be replaced by the ConversionException message.
        Parameters:
        valueConversionError - Message to be shown when conversion of the value fails
      • isEmpty

        public boolean isEmpty()
        Deprecated.
        Description copied from interface: Field
        Is the field empty? In general, "empty" state is same as null. As an exception, TextField also treats empty string as "empty".
        Specified by:
        isEmpty in interface Field<T>
        Returns:
        true if the field is empty, false otherwise
      • clear

        public void clear()
        Deprecated.
        Description copied from interface: Field
        Clears the value of the field.

        The field value is typically reset to the initial value of the field. Calling Field.isEmpty() on a cleared field must always returns true.

        Specified by:
        clear in interface Field<T>
      • isValidationVisible

        public boolean isValidationVisible()
        Deprecated.
        Is automatic, visible validation enabled? If automatic validation is enabled, any validators connected to this component are evaluated while painting the component and potential error messages are sent to client. If the automatic validation is turned off, isValid() and validate() methods still work, but one must show the validation in their own code.
        Returns:
        True, if automatic validation is enabled.
      • setValidationVisible

        public void setValidationVisible​(boolean validateAutomatically)
        Deprecated.
        Enable or disable automatic, visible validation. If automatic validation is enabled, any validators connected to this component are evaluated while painting the component and potential error messages are sent to client. If the automatic validation is turned off, isValid() and validate() methods still work, but one must show the validation in their own code.
        Parameters:
        validateAutomatically - True, if automatic validation is enabled.
      • setCurrentBufferedSourceException

        public void setCurrentBufferedSourceException​(Buffered.SourceException currentBufferedSourceException)
        Deprecated.
        Sets the current buffered source exception.
        Parameters:
        currentBufferedSourceException -
      • getCurrentBufferedSourceException

        protected Buffered.SourceException getCurrentBufferedSourceException()
        Deprecated.
        Gets the current buffered source exception.
        Returns:
        The current source exception
      • getConverter

        public Converter<T,​Object> getConverter()
        Deprecated.
        Gets the converter used to convert the property data source value to the field value.
        Returns:
        The converter or null if none is set.
      • setConverter

        public void setConverter​(Converter<T,​?> converter)
        Deprecated.
        Sets the converter used to convert the field value to property data source type. The converter must have a presentation type that matches the field type.
        Parameters:
        converter - The new converter to use.