package org.apache.wicket.markup.html.form;
An HTML form component knows how to validate itself. Validators that
implement IValidator can be added to the component. They will be evaluated in
the order they were added and the first Validator that returns an error
message determines the error message returned by the component.
FormComponents are not versioned by default. If you need versioning for your
FormComponents, you will need to call Form.setVersioned(true), which will set
versioning on for the form and all form component children.
If this component is required and that fails, the error key that is used is
the "Required"; if the type conversion fails, it will use the key
"IConverter". The keys that can be used in both are:
- ${input}: the input the user did give
- ${name}: the name of the component that failed
- ${label}: the label of the component
- Author(s):
- Jonathan Locke
- Eelco Hillenius
- Johan Compagner
- Igor Vaynberg (ivaynberg)
Visitor for traversing form components
Typesafe interface to code that is called when visiting a form component.
Called when visiting a form component
- Parameters:
formComponent
The form component- Returns:
- component
resource = prefix + getId() + "." + key;
message = localizer.getString(resource, formComponent, "");
message = localizer.getString(resource, formComponent, "");
Creates a new params map that additionaly contains the default input,
name, label parameters
- Parameters:
params
original params map- Returns:
- new params map
- Returns:
- value of label param for this form component
Change object to capture the required flag change
- Author(s):
- Igor Vaynberg (ivaynberg)
Whether this form component should save and restore state between
sessions. This is false by default.
Whether or not this component's value is required (non-empty)
Make empty strings null values boolean. Used by AbstractTextComponent
subclass.
Visits any form components inside component if it is a container, or
component itself if it is itself a form component
- Parameters:
component
starting point of the traversalvisitor
The visitor to call
if (container.size() > 0)
boolean visitChildren = true;
Raw Input entered by the user or NO_RAW_INPUT if nothing is filled in.
Type that the raw input string will be converted to
The list of validators for this form component as either an IValidator
instance or an array of IValidator instances.
Adds a validator to this form component.
Checks if the form component's 'required' requirement is met
- Returns:
- true if the 'required' requirement is met, false otherwise
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.
- Parameters:
error
validation error
message = "Could not locate error message for error: " + error.toString();
Gets the converter input. You typically should not override this method,
unless you are writing a
special form component that embeds other form
components that receive the real user input.
- Returns:
- value of input converted into appropriate type if any was set
- Returns:
- The parent form for this form component
Gets the request parameter for this component as a string.
- Returns:
- The value in the request for this component
if (input == null || input.length == 0)
Gets the request parameters for this component as strings.
- Returns:
- The values in the request for this component
if (values != null && values.length == 1 && values[0] == null)
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.
- Returns:
- The string to use as the form element's name attribute
if (inputName.equals("submit")) 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.
- Returns:
- The raw form input that is stored for this formcomponent
- Returns:
- the type to use when updating the model for this form component
Gets an unmodifiable list of validators for this FormComponent.
- Returns:
- List of validators
for (int i = 0; i < size; i++)
Gets current value for a form component.
This method can be called to know if this component really has raw input.
- Returns:
- boolean if this form component has rawinput.
Used by Form to tell the FormComponent that a new user input is available
if (input != null && input.length > 0 && input[0] != null)
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 had attribute
disabled="disabled" set.
- Returns:
- True if this component's input can be null. Returns true by
default.
- Returns:
- True if this component encodes data in a multipart form submit
- Returns:
- True if this component supports persistence AND it has been asked
to persist itself with setPersistent().
- Returns:
- whether or not this component's value is required
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 nescesarry as we don't want the form component models updated
with invalid input.
- Returns:
- valid whether this component is 'valid'
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.
The value will be made available to the validator property by means of
${label}. It does not have any specific meaning to FormComponent itself.
- Parameters:
labelModel- Returns:
- this for chaining
Sets the value for a form component this value will be split the string
with
VALUE_SEPARATOR and calls
setModelValue(String[]) with that.
- Deprecated:
- call or override setModelValue(String[])
- Parameters:
value
The value
Sets the value for a form component.
- Parameters:
value
The value
Sets whether this component is to be persisted.
- Parameters:
persistent
True if this component is to be persisted.- Returns:
- this for chaining
+ " does not support cookies");
Sets the required flag
- Parameters:
required- Returns:
- this for chaining
"FormComponent can't be not required when the type is primitive class: " + this);
Sets the type that will be used when updating the model for this
component. If no type is specified String type is assumed.
- Parameters:
type- Returns:
- this for chaining
Updates this components' model from the request, it expect that the
object is already converted through the convert() call. By default it
just does this:
setModelObject(getConvertedInput());
DO NOT CALL THIS METHOD DIRECTLY UNLESS YOU ARE SURE WHAT YOU ARE DOING.
USUALLY UPDATING YOUR MODEL IS HANDLED BY THE FORM, NOT DIRECTLY BY YOU.
Called to indicate that the user input is valid.
public final void valid()
Performs full validation of the form component, which consists of calling
validateRequired(), validateTypeConversion(), and validateValidators().
This method should only be used if the form component needs to be fully
validated outside the form process.
- Parameters:
validator
The validator to add to the validators Object (which may be an
array of IValidators or a single instance, for efficiency)
for (int i = 0; i < size; i++)
validators[size] = validator;
Gets validator from validators Object (which may be an array of
IValidators or a single instance, for efficiency) at the given index
- Parameters:
index
The index of the validator to get- Returns:
- The validator
- Returns:
- The number of validators in the validators Object (which may be
an array of IValidators or a single instance, for efficiency)
Converts and validates the conversion of the raw input string into the
object specified by
getType() and records any
errors. Converted value is available through
getConvertedInput()
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
return value != null && value.length > 0 && value[0] != null ? value[0].trim() : null;
- Returns:
- Value to return when model value is needed
Gets the request parameter for this component as an int.
- Returns:
- The value in the request for this component
+ string + "' not a valid integer"));
Gets the request parameter for this component as an int, using the given
default in case no corresponding request parameter was found.
- Parameters:
defaultValue
Default value to return if request does not have an integer
for this component- Returns:
- The value in the request for this component
protected final int inputAsInt(final int defaultValue)
+ "' is not a valid integer"));
Gets the request parameters for this component as ints.
- Returns:
- The values in the request for this component
final int[] ints = new int[strings.length];
for (int i = 0; i < strings.length; i++)
Processes the component tag.
Called by
onComponentTag(org.apache.wicket.markup.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.
- Parameters:
tag
the tag that is being rendered
tag.put("disabled", "disabled"); - Returns:
- True if this type of FormComponent can be persisted.
Checks if the raw input value is not null if this component is required
Validates this component using the component's validators.
for (i = 0; i < size; i++)