|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.wicket.Component
org.apache.wicket.MarkupContainer
org.apache.wicket.markup.html.WebMarkupContainer
org.apache.wicket.markup.html.form.LabeledWebMarkupContainer
org.apache.wicket.markup.html.form.FormComponent<T>
T
- The model object typepublic abstract class FormComponent<T>
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" if the conversion failed in a
converter, or "ConversionError" if type was explicitly specified via setType(Class)
or a
IPropertyReflectionAwareModel
was used. Notice that both "IConverter" and
"ConversionError" have a more specific variant of "key.classname" where classname is the type
that we failed to convert to. Classname is not full qualified, so only the actual name of the
class is used.
Property expressions that can be used in error messages are:
Nested Class Summary | |
---|---|
static class |
FormComponent.AbstractVisitor
Visitor for traversing form components |
static interface |
FormComponent.IVisitor
Typesafe interface to code that is called when visiting a form component. |
Nested classes/interfaces inherited from class org.apache.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 String |
VALUE_SEPARATOR
The value separator |
Fields inherited from class org.apache.wicket.Component |
---|
ENABLE, FLAG_CONFIGURED, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED6, FLAG_RESERVED7, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER |
Constructor Summary | |
---|---|
FormComponent(String id)
|
|
FormComponent(String id,
IModel<T> model)
|
Method Summary | |
---|---|
FormComponent<T> |
add(IValidator<T>... validators)
Adds a validator to this form component. |
FormComponent<T> |
add(IValidator<T> validator)
Adds a validator to this form component |
boolean |
checkRequired()
Checks if the form component's 'required' requirement is met by first checking isRequired() to see if it has to check for requirement. |
void |
clearInput()
Clears the user input. |
protected void |
convertInput()
Converts and validates the conversion of the raw input string into the object specified by getType() and records any errors. |
protected T |
convertValue(String[] value)
Subclasses should overwrite this if the conversion is not done through the type field and the IConverter . |
void |
error(IValidationError error)
Reports a validation error against this form component. |
T |
getConvertedInput()
Gets the converted input. |
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() . |
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() . |
Form<?> |
getForm()
|
String |
getInput()
Gets the request parameter for this component as a string. |
String[] |
getInputAsArray()
Gets the request parameters for this component as strings. |
String |
getInputName()
Gets the string to be used for the name attribute of the form element. |
IModel<T> |
getModel()
Gets model |
T |
getModelObject()
Gets model object |
protected String |
getModelValue()
|
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. |
Class<T> |
getType()
|
String |
getValidatorKeyPrefix()
|
List<IValidator<T>> |
getValidators()
Gets an unmodifiable list of validators for this FormComponent. |
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. |
boolean |
hasRawInput()
Returns whether this component 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. |
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()
Indicate that validation of this form component failed. |
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'. |
IValidatable<T> |
newValidatable()
Creates an IValidatable that can be used to validate this form component. |
protected void |
onComponentTag(ComponentTag tag)
Processes the component tag. |
protected void |
onDetach()
Sets the temporary converted input value to null. |
protected void |
onDisabled(ComponentTag tag)
Called by onComponentTag(ComponentTag) when the component is disabled. |
protected void |
onInvalid()
Handle invalidation |
protected void |
onValid()
Handle validation |
boolean |
processChildren()
Should children be traversed during visiting or should only the siblings be processed. |
void |
processInput()
This method will retrieve the request parameter, validate it, and if valid update the model. |
void |
setConvertedInput(T convertedInput)
Sets the converted input. |
FormComponent<T> |
setLabel(IModel<String> labelModel)
The value will be made available to the validator property by means of ${label}. |
void |
setModel(IModel<T> model)
Sets model |
void |
setModelObject(T object)
Sets model object |
void |
setModelValue(String value)
Deprecated. call or override setModelValue(String[]) |
void |
setModelValue(String[] value)
Sets the value for a form component. |
FormComponent<T> |
setPersistent(boolean persistent)
Sets whether this component is to be persisted. |
FormComponent<T> |
setRequired(boolean required)
Sets the required flag |
FormComponent<T> |
setType(Class<?> type)
Sets the type that will be used when updating the model for this component. |
protected boolean |
shouldTrimInput()
Determines whether or not this component should trim its input prior to processing it. |
protected boolean |
supportsPersistence()
|
protected String |
trim(String string)
Trims the input according to shouldTrimInput() |
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. |
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(), convertInput(), 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. |
static void |
visitComponentsPostOrder(Component component,
Component.IVisitor<Component> visitor)
Visits any form components inside component if it is a container, or component itself if it is itself a form component |
static void |
visitFormComponentsPostOrder(Component component,
FormComponent.IVisitor visitor)
Visits any form components inside component if it is a container, or component itself if it is itself a form component |
Methods inherited from class org.apache.wicket.markup.html.form.LabeledWebMarkupContainer |
---|
getLabel, setLabelInternal |
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer |
---|
getMarkupType, getWebPage, getWebRequest |
Methods inherited from class org.apache.wicket.MarkupContainer |
---|
add, addOrReplace, autoAdd, autoAdd, contains, findMarkupStream, get, get, getAssociatedMarkupStream, getMarkupStream, hasAssociatedMarkup, internalAdd, isTransparentResolver, iterator, iterator, newMarkupResourceStream, onAfterRenderChildren, onComponentTagBody, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderComponentTagBody, renderNext, replace, setDefaultModel, setMarkupStream, size, swap, 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 String VALUE_SEPARATOR
protected static final short FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL
Constructor Detail |
---|
public FormComponent(String id)
Component.Component(String)
public FormComponent(String id, IModel<T> model)
id
- model
- Component.Component(String, IModel)
Method Detail |
---|
public static final void visitFormComponentsPostOrder(Component component, FormComponent.IVisitor visitor)
component
- starting point of the traversalvisitor
- The visitor to callpublic static final void visitComponentsPostOrder(Component component, Component.IVisitor<Component> visitor)
component
- starting point of the traversalvisitor
- The visitor to callpublic final String getDefaultLabel()
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.
public final String getDefaultLabel(String defaultValue)
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
-
public final FormComponent<T> add(IValidator<T> validator)
validator
- validator to be added
this
for chaining
IllegalArgumentException
- if validator is nullIValidator
,
IValidatorAddListener
public final FormComponent<T> add(IValidator<T>... validators)
validators
- The validator(s) to be added
IllegalArgumentException
- if validator is nullIValidator
,
IValidatorAddListener
public boolean checkRequired()
isRequired()
to see if it has to check for requirement. If that is true then by
default it checks if the input is null or an empty String
Strings.isEmpty(CharSequence)
Subclasses that overwrite this method should also call isRequired()
first.
Strings.isEmpty(CharSequence)
,
isInputNullable()
public final void clearInput()
public void error(IValidationError error)
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 errorpublic final T getConvertedInput()
convertInput()
.
FormComponentPanel
often access this method when constructing their converted input
value which is often the combination of converted values of the embedded FormComponents
To access the model object resulted by the full form processing, use
getModelObject()
instead, that is an generified version of
Component.getDefaultModelObject()
public final void setConvertedInput(T convertedInput)
convertInput()
, in which case they should call this method to update the
input for this component instance.
convertedInput
- the converted inputpublic Form<?> getForm()
public String getInput()
public String[] getInputAsArray()
public String getInputName()
public final String getRawInput()
public final Class<T> getType()
public String getValidatorKeyPrefix()
Form.getValidatorKeyPrefix()
public final List<IValidator<T>> getValidators()
public final 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 boolean processChildren()
IFormVisitorParticipant
processChildren
in interface IFormVisitorParticipant
IFormVisitorParticipant.processChildren()
public final void processInput()
public FormComponent<T> setLabel(IModel<String> labelModel)
labelModel
-
@Deprecated public void setModelValue(String value)
VALUE_SEPARATOR
and calls setModelValue(String[]) with that.
value
- The valuepublic void setModelValue(String[] value)
value
- The valuepublic final FormComponent<T> setPersistent(boolean persistent)
persistent
- True if this component is to be persisted.
public final FormComponent<T> setRequired(boolean required)
required
-
public final FormComponent<T> setType(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.
updateModel
in interface IFormModelUpdateListener
public final void valid()
public void validate()
protected void convertInput()
getType()
and records any errors. Converted value is available through
getConvertedInput()
.
Usually the user should do custom conversions by specifying an IConverter
by
registering it with the application by overriding Application.getConverterLocator()
,
or at the component level by overriding Component.getConverter()
.
IConverterLocator
,
Application.newConverterLocator()
protected T convertValue(String[] value) throws ConversionException
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
ConversionException
- If input can't be convertedprotected 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 void internalOnModelChanged()
Component
Called anytime a model is changed via setModel or setModelObject.
internalOnModelChanged
in class Component
Component.internalOnModelChanged()
protected void onComponentTag(ComponentTag tag)
onComponentTag
in class Component
tag
- Tag to modifyComponent.onComponentTag(ComponentTag)
protected void onDetach()
onDetach
in class LabeledWebMarkupContainer
Component.onDetach()
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 onInvalid()
protected void onValid()
protected boolean shouldTrimInput()
true
protected final String trim(String string)
shouldTrimInput()
string
-
shouldTrimInput()
returns true, unchanged input otherwiseprotected boolean supportsPersistence()
protected final void validateRequired()
protected final void validateValidators()
public final IValidatable<T> newValidatable()
public final IModel<T> getModel()
public final void setModel(IModel<T> model)
model
- public final T getModelObject()
public final void setModelObject(T object)
object
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |