com.vaadin.ui.

Class AbstractField<T>

    • Constructor Detail

      • AbstractField

        public AbstractField()
    • Method Detail

      • setValue

        public void setValue​(T value)

        Description copied from interface: HasValue

        Sets the value of this object. If the new value is not equal to getValue(), fires a value change event. May throw IllegalArgumentException if the value is not acceptable.

        Implementation note: the implementing class should document whether null values are accepted or not.

        Specified by:

        setValue in interface HasValue<T>

        Parameters:

        value - the new value

      • setReadOnly

        public void setReadOnly​(boolean readOnly)

        Sets the read-only status in the state of this AbstractComponent. This method should be made public in Components that implement HasValue.

        The server ignores (potentially forged) value change requests from the client to fields that are read-only. Programmatically changing the field value via setValue(Object) is still possible.

        The read-only mode is distinct from the disabled state. When disabled, a component cannot be interacted with at all, and its content should be considered irrelevant or not applicable. In contrast, the user should still be able to read the content and otherwise interact with a read-only field even though changing the value is disallowed.

        Specified by:

        setReadOnly in interface HasValue<T>

        Overrides:

        setReadOnly in class AbstractComponent

        Parameters:

        readOnly - true to set read-only mode, false otherwise.

      • addValueChangeListener

        public Registration addValueChangeListener​(HasValue.ValueChangeListener<T> listener)

        Description copied from interface: HasValue

        Adds a value change listener. The listener is called when the value of this HasValue is changed either by the user or programmatically.

        Specified by:

        addValueChangeListener in interface HasValue<T>

        Parameters:

        listener - the value change listener, not null

        Returns:

        a registration for the listener

      • 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 AbstractComponent

        Parameters:

        design - The element to obtain the state from

        designContext - The DesignContext instance used for parsing the design

      • 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 AbstractComponent

        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

      • setValue

        protected boolean setValue​(T value,
                                   boolean userOriginated)

        Sets the value of this field if it has changed and fires a value change event. If the value originates from the client and this field is read-only, does nothing. Invokes doSetValue to actually store the value.

        Parameters:

        value - the new value to set

        userOriginated - true if this event originates from the client, false otherwise.

        Returns:

        true if the value was updated, false otherwise

      • isDifferentValue

        protected boolean isDifferentValue​(T newValue)

        Called when a new value is set to determine whether the provided new value is considered to be a change compared to the current value. This is used to determine whether doSetValue(Object) should be called and a value change event fired.

        Parameters:

        newValue - the new value candidate to check, may be null

        Returns:

        true if the provided value is considered to be different and a value change event should be fired; false if the values are considered to be the same and no value change should be fired

      • doSetValue

        protected abstract void doSetValue​(T value)

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

        Parameters:

        value - the new value of the field

        Throws:

        IllegalArgumentException - if the value is invalid

      • createValueChange

        protected HasValue.ValueChangeEvent<T> createValueChange​(T oldValue,
                                                                 boolean userOriginated)

        Returns a new value change event instance.

        Parameters:

        oldValue - the value of this field before this value change event

        userOriginated - true if this event originates from the client, false otherwise.

        Returns:

        the new event

      • getState

        protected AbstractFieldState getState()

        Description copied from class: AbstractComponent

        Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

        Overrides:

        getState in class AbstractComponent

        Returns:

        updated component shared state

      • setTabIndex

        public void setTabIndex​(int tabIndex)

        Description copied from interface: Component.Focusable

        Sets the tabulator index of the Focusable component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.

         Form loginBox = new Form();
         loginBox.setCaption("Login");
         layout.addComponent(loginBox);
        
         // Create the first field which will be focused
         TextField username = new TextField("User name");
         loginBox.addField("username", username);
        
         // Set focus to the user name
         username.focus();
        
         TextField password = new TextField("Password");
         loginBox.addField("password", password);
        
         Button login = new Button("Login");
         loginBox.getFooter().addComponent(login);
        
         // An additional component which natural focus order would
         // be after the button.
         CheckBox remember = new CheckBox("Remember me");
         loginBox.getFooter().addComponent(remember);
        
         username.setTabIndex(1);
         password.setTabIndex(2);
         remember.setTabIndex(3); // Different than natural place
         login.setTabIndex(4);
         

        After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.

        If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.

        A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.

        Specified by:

        setTabIndex in interface Component.Focusable

        Parameters:

        tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.

        See Also:

        Component.Focusable.getTabIndex()