Class AbstractInput

    • Constructor Detail

      • AbstractInput

        public AbstractInput()
    • Method Detail

      • addValidator

        public void addValidator​(FieldValidator validator)
        Adds a validator to the input field. Validators are not automatically called on form submission. Using a ValidatingAction or an explicit call to WComponent.validate(List) will trigger validation on a WComponent tree.
        Specified by:
        addValidator in interface Input
        Parameters:
        validator - the validator to add.
      • validateComponent

        protected void validateComponent​(List<Diagnostic> diags)
        Override WComponent's validatorComponent in order to use the validators which have been added to this input field. Subclasses may still override this method, but it is suggested to call super.validateComponent to ensure that the validators are still used.
        Overrides:
        validateComponent in class AbstractWComponent
        Parameters:
        diags - the list into which any validation diagnostics are added.
      • createMandatoryDiagnostic

        protected Diagnostic createMandatoryDiagnostic()

        This method is called by validateComponent to create the mandatory diagnostic error message if the mandatory validation check does not pass.

        Subclasses may override this method to customise the message, however in most cases it is easier to supply a custom error message pattern to the setMandatory method.

        Returns:
        a new diagnostic for when mandatory validation fails.
      • setActionOnChange

        public void setActionOnChange​(Action actionOnChange)
        Sets the action that you want run if the input is changed by the user. The action command will be set to the new value of the input.
        Specified by:
        setActionOnChange in interface Input
        Parameters:
        actionOnChange - the action to execute when the input is changed by the user.
      • getActionOnChange

        public Action getActionOnChange()
        Specified by:
        getActionOnChange in interface Input
        Returns:
        the action to execute when the input is changed by the user.
      • getActionObject

        public Object getActionObject()
        Returns the data object that has been associated with this input component, else null. For convenience, this data object is passed to the execute() method of the button's associated Action, in the ActionEvent parameter.
        Specified by:
        getActionObject in interface Input
        Returns:
        the data object that has been associated with this input component.
      • setActionObject

        public void setActionObject​(Object data)
        Associates this input with a data object that can be easily accessed in the execute() method of the associated Action.
        Specified by:
        setActionObject in interface Input
        Parameters:
        data - the data object.
      • getActionCommand

        public String getActionCommand()
        Same as {#getValueAsString()}. This method exists simply to clarify the relationship between the input component, its Action, and the ActionEvent sent to the execute() method of the Action.
        Specified by:
        getActionCommand in interface Input
        Returns:
        the current selection, as a string.
      • setDefaultSubmitButton

        public void setDefaultSubmitButton​(WButton defaultSubmitButton)
        Sets the button that should be submitted when the user hits enter key and cursor is inside this input field.
        Specified by:
        setDefaultSubmitButton in interface Input
        Parameters:
        defaultSubmitButton - the default submit button for this field.
      • getDefaultSubmitButton

        public WButton getDefaultSubmitButton()
        Specified by:
        getDefaultSubmitButton in interface Input
        Returns:
        the button that will be submitted if the user hits the enter key when the cursor is in this field.
      • setMandatory

        public void setMandatory​(boolean mandatory,
                                 String message)
        Set whether or not this input is mandatory, and customise the error message that will be displayed.
        Specified by:
        setMandatory in interface Input
        Parameters:
        mandatory - true for mandatory, false for optional.
        message - the message to display to the user on mandatory validation failure.
      • setMandatory

        public void setMandatory​(boolean mandatory)
        Set whether or not this component is mandatory.
        Specified by:
        setMandatory in interface Mandatable
        Parameters:
        mandatory - true for mandatory, false for optional.
      • isMandatory

        public boolean isMandatory()
        Indicates whether or not this component is mandatory.
        Specified by:
        isMandatory in interface Mandatable
        Returns:
        true if the input is mandatory, false otherwise.
      • isReadOnly

        public boolean isReadOnly()
        Indicates whether the input is read only in the given context.
        Specified by:
        isReadOnly in interface Input
        Returns:
        true if the input is read only, otherwise false.
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
        Sets whether the input is read only.
        Specified by:
        setReadOnly in interface Input
        Parameters:
        readOnly - if true, the input is read only. If false, it is editable.
      • isDisabled

        public boolean isDisabled()
        Indicates whether the Disableable is disabled.
        Specified by:
        isDisabled in interface Disableable
        Returns:
        true if the Disableable is disabled, otherwise false.
      • setDisabled

        public void setDisabled​(boolean disabled)
        Sets whether the Disableable is disabled.
        Specified by:
        setDisabled in interface Disableable
        Parameters:
        disabled - if true, the Disableable is disabled. If false, it is enabled.
      • handleRequest

        public final void handleRequest​(Request request)
        Override handleRequest in order to perform consistent processing for input components.

        To protect against client-side tampering of the request, disabled/readonly input fields will not have their handle request processing performed.

        This method will call doHandleRequest(Request) for input components to process the request. If the input component has changed, then this method will call doHandleChanged() and set the isChangedInLastRequest() flag.

        Specified by:
        handleRequest in interface WComponent
        Overrides:
        handleRequest in class AbstractWComponent
        Parameters:
        request - the request being responded to.
      • beforeHandleRequest

        protected boolean beforeHandleRequest​(Request request)
        Handle before handle request processing.
        Parameters:
        request - the request being responded to.
        Returns:
        true to continue
      • doHandleRequest

        protected abstract boolean doHandleRequest​(Request request)
        Specific handle request processing for an input component is provided here.

        Input components are required to determine if the component has changed in the request, set the component data to the new value (if changed) and return the changed flag.

        Parameters:
        request - the request being responded to.
        Returns:
        true if the input component has changed, otherwise return false
      • doHandleChanged

        protected void doHandleChanged()
        Perform change logic for this component.

        Reset focus ONLY if the current Request is an Ajax request. See https://github.com/BorderTech/wcomponents/issues/501.

      • isPresent

        protected boolean isPresent​(Request request)
        Determine if this component is on the Request.
        Parameters:
        request - the request being responded to.
        Returns:
        true if this component is on the Request, otherwise return false.
      • getValue

        public Object 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
        Returns:
        the value of the component returned by DataBound.getData() in the correct format.
      • getValueAsString

        public String getValueAsString()
        Retrieves a String representation of the input field's value.
        Specified by:
        getValueAsString in interface Input
        Returns:
        the String representation of the input field's value
      • isEmpty

        public boolean isEmpty()
        Indicates whether this input field is empty. An input is considered empty if the value is null or an empty String.
        Specified by:
        isEmpty in interface Input
        Returns:
        true if this input field is empty, false otherwise.
      • isChangedInLastRequest

        public boolean isChangedInLastRequest()
        Indicates if the input component was changed in the last request.
        Specified by:
        isChangedInLastRequest in interface Input
        Returns:
        true if the input was changed in the last request.
      • setChangedInLastRequest

        protected void setChangedInLastRequest​(boolean changed)
        Set the changed flag to indicate if the component changed in the last request.
        Parameters:
        changed - true if the value changed in the request
      • isCurrentAjaxTrigger

        public final boolean isCurrentAjaxTrigger()
        Returns:
        true if the current Input is also the current Ajax trigger.
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component, for debugging purposes.
      • showIndicatorsForComponent

        protected void showIndicatorsForComponent​(List<Diagnostic> diags,
                                                  int severity)
        Iterates over the Diagnostics and finds the diagnostics that related to the current component.
        Parameters:
        diags - A List of Diagnostic objects.
        severity - A Diagnostic severity code. e.g. Diagnostic.ERROR
      • showErrorIndicatorsForComponent

        protected final void showErrorIndicatorsForComponent​(List<Diagnostic> diags)

        This does not affect the diag list at all. The ValidatableComponent should visually mark any fields or blocks that have errors in the given diag list.

        Overrides:
        showErrorIndicatorsForComponent in class AbstractWComponent
        Parameters:
        diags - the list of diagnostics for this component.
      • showWarningIndicatorsForComponent

        protected final void showWarningIndicatorsForComponent​(List<Diagnostic> diags)

        This does not affect the diag list at all. The ValidatableComponent should visually mark any fields or blocks that have warnings in the given diag list.

        Overrides:
        showWarningIndicatorsForComponent in class AbstractWComponent
        Parameters:
        diags - the list of diagnostics for this component.
      • getDiagnostics

        public List<Diagnostic> getDiagnostics​(int severity)
        Specified by:
        getDiagnostics in interface Diagnosable
        Parameters:
        severity - the diagnostic level we are interested in
        Returns:
        the list of diagnostics for the component.
      • getComponentModel

        protected AbstractInput.InputModel 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 WBeanComponent
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected AbstractInput.InputModel 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 WBeanComponent
        Returns:
        the model for this component