|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wicket.Component wicket.MarkupContainer wicket.markup.html.WebMarkupContainer wicket.markup.html.form.FormComponent
public abstract class FormComponent
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 "RequiredValidator"; if the type conversion fails, it will use the key "TypeValidator". The keys that can be used in both are:
Nested Class Summary | |
---|---|
static interface |
FormComponent.IVisitor
Typesafe interface to code that is called when visiting a form component. |
Nested classes/interfaces inherited from class wicket.Component |
---|
Component.ComponentModelChange, Component.EnabledChange, Component.VisibilityChange |
Field Summary | |
---|---|
protected static short |
FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL
Make empty strings null values boolean. |
static java.lang.String |
VALUE_SEPARATOR
The value separator |
Fields inherited from class wicket.Component |
---|
ENABLE, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PATH_SEPARATOR, RENDER |
Constructor Summary | |
---|---|
FormComponent(java.lang.String id)
|
|
FormComponent(java.lang.String id,
IModel model)
|
Method Summary | |
---|---|
FormComponent |
add(IValidator validator)
Adds a validator to this form component. |
boolean |
checkRequired()
Checks if the form component's 'required' requirement is met |
void |
clearInput()
Clears the user input. |
protected void |
convert()
Converts and validates the conversion of the raw input string into the object specified by getType() and records any
errors. |
protected java.lang.Object |
convertValue(java.lang.String[] value)
Subclasses should overwrite this if the conversion is not done through the type field and the IConverter. |
void |
error(java.util.List resourceKeys,
java.util.Map args)
Builds and reports an error message. |
java.lang.Object |
getConvertedInput()
|
Form |
getForm()
|
java.lang.String |
getInput()
Gets the request parameter for this component as a string. |
java.lang.String[] |
getInputAsArray()
Gets the request parameters for this component as strings. |
java.lang.String |
getInputName()
Gets the string to be used for the name attribute of the form element. |
IModel |
getLabel()
The value will be made available to the validator property by means of ${label}. |
protected java.lang.String |
getModelValue()
|
java.lang.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. |
java.lang.Class |
getType()
|
java.lang.String |
getValidatorKeyPrefix()
|
java.util.List |
getValidators()
Gets an unmodifiable list of validators for this FormComponent. |
java.lang.String |
getValue()
Gets current value for a form component. |
boolean |
hasRawInput()
This method can be called to know if this component really has raw input. |
protected int |
inputAsInt()
Gets the request parameter for this component as an int. |
protected 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. |
protected int[] |
inputAsIntArray()
Gets the request parameters for this component as ints. |
protected java.lang.String[] |
inputAsStringArray()
Deprecated. Use getInputAsArray() instead |
void |
inputChanged()
Used by Form to tell the FormComponent that a new user input is available |
protected void |
internalOnModelChanged()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. |
void |
invalid()
Called to indicate that |
boolean |
isInputNullable()
Gets whether this component's input can be null. |
boolean |
isMultiPart()
|
boolean |
isPersistent()
|
boolean |
isRequired()
|
boolean |
isValid()
Gets whether this component is 'valid'. |
boolean |
isValidated()
Gets whether this component is to be validated. |
protected void |
onComponentTag(ComponentTag tag)
Processes the component tag. |
protected void |
onDetach()
Called to allow a component to detach resources after use. |
protected void |
onDisabled(ComponentTag tag)
Called by onComponentTag(ComponentTag) when the component is
disabled. |
protected void |
onInvalid()
Handle invalidation |
protected void |
onValid()
Handle validation |
void |
processInput()
This method will retrieve the request parameter, validate it, and if valid update the model. |
FormComponent |
setLabel(IModel labelModel)
The value will be made available to the validator property by means of ${label}. |
void |
setModelValue(java.lang.String value)
Sets the value for a form component this value will be split the string with VALUE_SEPARATOR and calls
setModelValue(String[]) with that. |
void |
setModelValue(java.lang.String[] value)
Sets the value for a form component. |
FormComponent |
setPersistent(boolean persistent)
Sets whether this component is to be persisted. |
FormComponent |
setRequired(boolean required)
Sets the required flag |
FormComponent |
setType(java.lang.Class type)
Sets the type that will be used when updating the model for this component. |
protected boolean |
supportsPersistence()
|
void |
updateModel()
Updates this components' model from the request, it expect that the object is already converted through the convert() call. |
void |
valid()
Called to indicate that the user input is valid. |
void |
validate()
Performs full validation of the form component, which consists of calling validateRequired(), validateTypeConversion(), and validateValidators(). |
protected void |
validateRequired()
Checks if the raw input value is not null if this component is required |
protected void |
validateValidators()
Validates this component using the component's validators. |
Methods inherited from class wicket.markup.html.WebMarkupContainer |
---|
getMarkupType, getWebPage |
Methods inherited from class wicket.MarkupContainer |
---|
add, autoAdd, contains, findMarkupStream, get, getAssociatedMarkupStream, getMarkupStream, internalAdd, internalAttach, internalDetach, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onComponentTagBody, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static java.lang.String VALUE_SEPARATOR
protected static final short FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL
Constructor Detail |
---|
public FormComponent(java.lang.String id)
Component.Component(String)
public FormComponent(java.lang.String id, IModel model)
Component.Component(String, IModel)
Method Detail |
---|
public final FormComponent add(IValidator validator)
validator
- The validator
public final boolean checkRequired()
public final void clearInput()
public final void error(java.util.List resourceKeys, java.util.Map args)
This function will iterate over the list of resource keys and try to find
a resource message that matches. Each key is first tried verbatim, and
then a key of form prefix.key is tried; prefix comes from
getValidatorKeyPrefix()
.
If a message is found, any variables in it with form ${varname} will be interpolated given the arguments in the args parameter.
This method will add a few default arguments to the args map if they are not already present:
getLabel()
model
resourceKeys
- list of resource keys to tryargs
- argument substituion map with format map:varname->varvaluepublic final java.lang.Object getConvertedInput()
public Form getForm()
public java.lang.String getInput()
public java.lang.String[] getInputAsArray()
public java.lang.String getInputName()
public IModel getLabel()
public final java.lang.String getRawInput()
public final java.lang.Class getType()
public java.lang.String getValidatorKeyPrefix()
Form.getValidatorKeyPrefix()
public final java.util.List getValidators()
public final java.lang.String getValue()
public final boolean hasRawInput()
public final void inputChanged()
public final void invalid()
public boolean isInputNullable()
disabled="disabled"
set.
public boolean isMultiPart()
public final boolean isPersistent()
public boolean isRequired()
public final boolean isValid()
public final boolean isValidated()
public final void processInput()
public FormComponent setLabel(IModel labelModel)
labelModel
-
public void setModelValue(java.lang.String value)
VALUE_SEPARATOR
and calls
setModelValue(String[]) with that.
value
- The valuepublic void setModelValue(java.lang.String[] value)
value
- The valuepublic final FormComponent setPersistent(boolean persistent)
persistent
- True if this component is to be persisted.
public final FormComponent setRequired(boolean required)
required
-
public final FormComponent setType(java.lang.Class type)
type
-
public void updateModel()
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.
public final void valid()
public final void validate()
protected final void convert()
getType()
and records any
errors. Converted value is available thorugh
getConvertedInput()
protected java.lang.Object convertValue(java.lang.String[] value) throws ConversionException
value
- The value can be the getInput() or through a cookie
ConversionException
- If input can't be convertedprotected java.lang.String getModelValue()
protected final int inputAsInt()
protected final int inputAsInt(int defaultValue)
defaultValue
- Default value to return if request does not have an integer
for this component
protected final int[] inputAsIntArray()
protected final java.lang.String[] inputAsStringArray()
getInputAsArray()
instead
protected void internalOnModelChanged()
Component
internalOnModelChanged
in class Component
Component.internalOnModelChanged()
protected void onComponentTag(ComponentTag tag)
onComponentTag
in class Component
tag
- Tag to modifyComponent.onComponentTag(ComponentTag)
protected void onDisabled(ComponentTag tag)
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 renderedprotected void onDetach()
Component
onDetach
in class Component
protected void onInvalid()
protected void onValid()
protected boolean supportsPersistence()
protected final void validateRequired()
protected final void validateValidators()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |