Class WMultiTextField

  • All Implemented Interfaces:
    AjaxTarget, AjaxTrigger, BeanAware, BeanBound, BeanProviderBound, DataBound, Diagnosable, Disableable, Input, Labelable, Mandatable, MultiInputComponent, Placeholderable, SubordinateTarget, WComponent, WebComponent, Serializable

    public class WMultiTextField
    extends AbstractInput
    implements AjaxTrigger, AjaxTarget, SubordinateTarget, MultiInputComponent, Placeholderable

    The WMultiTextField component allows multiple text input elements to be generated dynamically on the client without requiring the page to be reloaded. This component takes its appearance and attributes from a regular text input but allows for one or more items of text to be entered via the add link adjacent to the right of the text input.

    This component is useful in instances where the user needs to enter one or more text items into the interfaces for a particular field. For instance, the user may have one or more aliases that need to be entered into the system.

    The following attributes can be set on WMultiTextField:

    • MaxInputs: The maximum number of text inputs the user can add to the component. Client-side functionality will stop users adding more than the allowable number of inputs via the UI. This class chops off any excess inputs if an attempt is made to add them programmatically.
    • MaxLength: The maximum length of the text fields rendered to allow user text entry.
    • Columns: The size of the text fields rendered to allow user text entry.
    Since:
    1.0.0
    Author:
    Christina Harris, Jonathan Austin
    See Also:
    Serialized Form
    • Constructor Detail

      • WMultiTextField

        public WMultiTextField()
        Creates an empty WMultiTextField.
      • WMultiTextField

        public WMultiTextField​(String[] inputs)
        Creates a WMultiTextField with the default input values.
        Parameters:
        inputs - the default set of values.
    • Method Detail

      • getValue

        public String[] getValue()
        Provide the value of the component returned by DataBound.getData() in the correct format.

        If required, this method can convert the data into the correct type and also do any validation before the value is used.

        Specified by:
        getValue in interface Input
        Overrides:
        getValue in class AbstractInput
        Returns:
        the value of the component returned by DataBound.getData() in the correct format.
      • setData

        public void setData​(Object data)
        Sets the data that this component displays/edits. For bean aware components, this should only be called from handleRequest to set user-entered data.
        Specified by:
        setData in interface DataBound
        Overrides:
        setData in class WBeanComponent
        Parameters:
        data - the data to set
      • getTextInputs

        public String[] getTextInputs()
        Returns:
        The text inputs of this component.
      • setTextInputs

        public void setTextInputs​(String[] inputs)
        Set the text inputs of this component.
        Parameters:
        inputs - The text inputs to set.
      • getMaxInputs

        public int getMaxInputs()
        Returns:
        The maximum number of strings that can be associated to this component.
      • setMaxInputs

        public void setMaxInputs​(int max)
        Set the maximum number of strings/inputs that can be associated to this component.
        Parameters:
        max - The maximum number of text inputs.
      • getColumns

        public int getColumns()
        Returns:
        the width of the input field in characters.
      • setColumns

        public void setColumns​(int columns)
        Sets the width of the input field in characters.
        Parameters:
        columns - the number of characters to display.
      • getMinLength

        public int getMinLength()
        Returns:
        the minimum number of characters that the user can enter into the multi text field.
      • setMinLength

        public final void setMinLength​(int minLength)
        Set the minimum number of characters that the user can enter into the multi text field.

        Setting the minimum number of characters will not make a field mandatory as the validation is only applied once the user has entered some text. Use AbstractInput.setMandatory(boolean) to make a field mandatory, which can be used in combination with setMinLength.

        Parameters:
        minLength - the minimum number of characters to allow.
      • getMaxLength

        public int getMaxLength()
        Returns:
        the maximum number of characters that the user can enter into the multi text field.
      • setMaxLength

        public final void setMaxLength​(int maxLength)
        Set the maximum number of characters that the user can enter into the multi text field.
        Parameters:
        maxLength - the maximum number of characters to allow.
      • setPattern

        public final void setPattern​(String pattern)
        The pattern to validate against.

        The pattern must be supported natively by your target user agent (e.g. browser).

        It is expected the WLabel for this component describes the required format of the component.

        Parameters:
        pattern - the pattern to validate against.
      • getPattern

        public String getPattern()
        Returns:
        the pattern to validate against.
      • setPlaceholder

        public void setPlaceholder​(String placeholder)
        Set placeholder text which will appear in the field if it is editable and has no content.
        Specified by:
        setPlaceholder in interface Placeholderable
        Parameters:
        placeholder - The text to set as the placeholder.
      • getPlaceholder

        public String getPlaceholder()
        Get the placeholder text, if explicitly set.
        Specified by:
        getPlaceholder in interface Placeholderable
        Returns:
        The placeholder text, if set.
      • doHandleRequest

        protected boolean doHandleRequest​(Request request)
        Set the inputs based on the incoming request. The text input values are set as an array of strings on the parameter with this name AbstractWComponent.getName(). Any empty strings will be ignored.
        Specified by:
        doHandleRequest in class AbstractInput
        Parameters:
        request - the current request.
        Returns:
        true if the inputs have changed, otherwise return false
      • getRequestValue

        public String[] getRequestValue​(Request request)
        Provide the value of the component on the Request.

        If the component is not on the request, the components current value will be provided.

        Specified by:
        getRequestValue in interface Input
        Parameters:
        request - the request being responded to.
        Returns:
        the value of this component on the Request, or its current state if it is not on the request.
      • validateComponent

        protected void validateComponent​(List<Diagnostic> diags)
        Override validateComponent to perform further validation.
        Overrides:
        validateComponent in class AbstractInput
        Parameters:
        diags - the list into which any validation diagnostics are added.
      • getComponentModel

        protected WMultiTextField.MultiTextFieldModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class AbstractInput
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WMultiTextField.MultiTextFieldModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractInput
        Returns:
        the model for this component