Class FormComponent<T>

    • Method Detail

      • onBeforeRender

        protected void onBeforeRender()
        Description copied from class: Component
        Called on all visible components before any component is rendered.

        NOTE: If you override this, you *must* call super.onBeforeRender() within your implementation. Because this method is responsible for cascading Component.onBeforeRender() call to its children it is strongly recommended that super call is made at the end of the override.

        Changes to the component tree can be made only before calling super.onBeforeRender().
        onBeforeRender in class Component
        See Also:
      • visitFormComponentsPostOrder

        public static <R> R visitFormComponentsPostOrder​(Component component,
                                                         IVisitor<? extends FormComponent<?>,​R> visitor)
        Visits any form components inside component if it is a container, or component itself if it is itself a form component
        Type Parameters:
        R - the type of the visitor's result
        component - starting point of the traversal
        visitor - The visitor to call
        the visitor's result
      • visitComponentsPostOrder

        public static <R> R visitComponentsPostOrder​(Component component,
                                                     IVisitor<Component,​R> visitor)
        Visits any form components inside component if it is a container, or component itself if it is itself a form component
        Type Parameters:
        R - the type of the visitor's result
        component - starting point of the traversal
        visitor - The visitor to call
        the visitor's result
      • getDefaultLabel

        public final String getDefaultLabel()
        Gets the string the component would use as a label when one was requested but no label model was set via LabeledWebMarkupContainer.getLabel(). The value of this string is usually set in a property file; if the value is not set the default value equivalent to component id will be returned.
        localized label
      • getDefaultLabel

        public final String getDefaultLabel​(String defaultValue)
        Gets the string the component would use as a label when one was requested but no label model was set via LabeledWebMarkupContainer.getLabel(). The value of this string is usually set in a property file; if the value is not set the defaultValue will be returned.
        defaultValue -
        localized label
      • clearInput

        public void clearInput()
        Clears the user input.
      • error

        public void error​(IValidationError error)
        Reports a validation error against this form component. The actual error is reported by creating a ValidationErrorFeedback object that holds both the validation error and the generated error message - so a custom feedback panel can have access to both.
        error - validation error
      • setConvertedInput

        public final void setConvertedInput​(T convertedInput)
        Sets the converted input. This method is typically not called by clients, unless they override convertInput(), in which case they should call this method to update the input for this component instance.
        convertedInput - the converted input
      • getForm

        public Form<?> getForm()
        The parent form for this form component
      • getInput

        public String getInput()
        Gets the request parameter for this component as a string.
        The value in the request for this component
      • getInputAsArray

        public String[] getInputAsArray()
        Gets the request parameters for this component as strings.
        The values in the request for this component
      • getParameterValues

        protected List<StringValuegetParameterValues​(String inputName)
        Reads the value(s) of the request parameter with name inputName from either the query parameters for GET method or the request body for POST method.
        inputName - The name of the request parameter
        The parameter's value(s)
      • getInputName

        public String getInputName()
        Gets the string to be used for the name attribute of the form element. Generated using the path from the form to the component, excluding the form itself. Override it if you want even a smaller name. E.g. if you know for sure that the id is unique within a form.
        The string to use as the form element's name attribute
      • getRawInput

        public final String getRawInput()
        Use hasRawInput() to check if this component has raw input because null can mean 2 things: It doesn't have rawinput or the rawinput is really null.
        The raw form input that is stored for this formcomponent
      • getType

        public final Class<TgetType()
        the type to use when updating the model for this form component
      • getValidators

        public final List<IValidator<? super T>> getValidators()
        Gets an unmodifiable list of validators for this FormComponent.
        List of validators
      • getValue

        public final String getValue()
        Gets current value for a form component, which can be either input data entered by the user, or the component's model object if no input was provided.
        The value
      • hasRawInput

        public final boolean hasRawInput()
        Returns whether this component has raw input. Raw input is unconverted input straight from the client.
        boolean whether this component has raw input.
      • inputChanged

        public final void inputChanged()
        Used by Form to tell the FormComponent that a new user input is available
      • invalid

        public final void invalid()
        Indicate that validation of this form component failed.
      • isInputNullable

        public boolean isInputNullable()
        Gets whether this component's input can be null. By default, components that do not get input will have null values passed in for input. However, component TextField is an example (possibly the only one) that never gets a null passed in, even if the field is left empty UNLESS it has attribute disabled="disabled" set.
        True if this component's input can be null. Returns true by default.
      • isMultiPart

        public boolean isMultiPart()
        True if this component encodes data in a multipart form submit
      • isRequired

        public boolean isRequired()
        whether or not this component's value is required
      • isValid

        public final boolean isValid()
        Gets whether this component is 'valid'. Valid in this context means that no validation errors were reported the last time the form component was processed. This variable not only is convenient for 'business' use, but is also necessary as we don't want the form component models updated with invalid input.
        valid whether this component is 'valid'
      • processInput

        public final void processInput()
        This method will retrieve the request parameter, validate it, and if valid update the model. These are the same steps as would be performed by the form. This is useful when a formcomponent is used outside a form.
      • setModelValue

        public void setModelValue​(String[] value)
        THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT! Sets the value for a form component.
        value - The value
      • setRequired

        public final FormComponent<TsetRequired​(boolean required)
        Sets the required flag
        required -
        this for chaining
      • setType

        public FormComponent<TsetType​(Class<?> type)
        Sets the type that will be used when updating the model for this component. If no type is specified String type is assumed.
        type -
        this for chaining
      • updateModel

        public void updateModel()
        Updates this components model from the request, it expects that the object is already converted through the convertInput() call that is called by the validate() method when a form is being processed. By default it just does this:
        Specified by:
        updateModel in interface IFormModelUpdateListener
      • valid

        public final void valid()
        Called to indicate that the user input is valid.
      • validate

        public void validate()
        Performs full validation of the form component, which consists of calling validateRequired(), convertInput(), and validateValidators(). This method should only be used if the form component needs to be fully validated outside the form process.
      • newValidationError

        protected ValidationError newValidationError​(ConversionException cause)
        This method is called, when the validation triggered by convertInput() failed with a ConversionException, to construct a ValidationError based on the exception.

        Override this method to modify the ValidationError object, e.g. add a custom variable for message substitution:

         new FormComponent<T>(id)
                protected ValidationError newValidationError(ConversionException cause)
                        return super.newValidationError(cause).setVariable("foo", foovalue);
        cause - the original cause
      • convertValue

        protected T convertValue​(String[] value)
                          throws ConversionException
        Subclasses should overwrite this if the conversion is not done through the type field and the IConverter. WARNING: this method may be removed in future versions. If conversion fails then a ConversionException should be thrown
        value - The value can be the getInput() or through a cookie
        The converted value. default returns just the given value
        ConversionException - If input can't be converted
      • getModelValue

        protected String getModelValue()
        Value to return when model value is needed
      • inputAsInt

        protected final int inputAsInt()
        Gets the request parameter for this component as an int.
        The value in the request for this component
      • inputAsInt

        protected final int inputAsInt​(int defaultValue)
        Gets the request parameter for this component as an int, using the given default in case no corresponding request parameter was found.
        defaultValue - Default value to return if request does not have an integer for this component
        The value in the request for this component
      • inputAsIntArray

        protected final int[] inputAsIntArray()
        Gets the request parameters for this component as ints.
        The values in the request for this component
      • onDisabled

        protected void onDisabled​(ComponentTag tag)
        Called by onComponentTag(ComponentTag) when the component is disabled. By default, this method will add a disabled="disabled" attribute to the tag. Components may override this method to tweak the tag as they think is fit.
        tag - the tag that is being rendered
      • onInvalid

        protected void onInvalid()
        Handle invalidation
      • onValid

        protected void onValid()
        Handle validation
      • shouldTrimInput

        protected boolean shouldTrimInput()
        Determines whether or not this component should trim its input prior to processing it. The default value is true
        True if the input should be trimmed.
      • validateRequired

        protected final void validateRequired()
        Checks if the raw input value is not null if this component is required.
      • reportRequiredError

        protected void reportRequiredError()
        Reports required error against this component
      • validateValidators

        protected final void validateValidators()
        Validates this component using the component's validators.
      • newValidatable

        public final IValidatable<TnewValidatable()
        Creates an IValidatable that can be used to validate this form component. This validatable incorporates error key lookups that correspond to this form component. This method is useful when validation needs to happen outside the regular validation workflow but error messages should still be properly reported against the form component.
        IValidatable for this form component
      • updateAutoLabels

        public final void updateAutoLabels​(IPartialPageRequestHandler target,
                                           boolean checkAuto)
        Updates auto label css classes such as error/required during ajax updates when the labels may not be directly repainted in the response.
        target - The IPartialPageRequestHandler
        checkAuto - if true then we check is the related auto-label is marked as auto before updating it.
      • updateCollectionModel

        public static <S> void updateCollectionModel​(FormComponent<Collection<S>> formComponent)
        Update the model of a FormComponent containing a Collection. If the model object does not yet exists, a new suitable collection is filled with the converted input and used as the new model object. Otherwise the existing collection is modified in-place, then IModel.setObject(Object) is called with the same instance: it allows the Model to be notified of changes even when Model.getObject() returns a different Collection at every invocation.
        Type Parameters:
        S - collection type
        formComponent - the form component to update
        WicketRuntimeException - if the existing model object collection is unmodifiable and no setter exists
        See Also: