wicket.markup.html.form
Class FormComponent

java.lang.Object
  extended bywicket.Component
      extended bywicket.MarkupContainer
          extended bywicket.markup.html.WebMarkupContainer
              extended bywicket.markup.html.form.FormComponent
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
wicket.markup.html.form.AbstractChoice, wicket.markup.html.form.AbstractTextComponent, Button, CheckBox, FileUploadField

public abstract class FormComponent
extends WebMarkupContainer

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.

Author:
Jonathan Locke, Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
static interface FormComponent.IVisitor
          Typesafe interface to code that is called when visiting a form component
 
Nested classes inherited from class wicket.Component
Component.ComponentModelChange, Component.VisibilityChange
 
Field Summary
protected static short FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL
          Make empty strings null values boolean
protected static java.lang.String NO_INVALID_INPUT
          Special flag value to indicate when there is no invalid input, since null is a valid value!
 
Fields inherited from class wicket.Component
FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4
 
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.
 Form getForm()
           
 java.lang.String getInput()
          Gets the request parameter for this component as a string.
protected  java.lang.String getModelValue()
           
 java.lang.Class getValidationType()
          Gets the type for any TypeValidator assigned to this component.
 java.util.List getValidators()
          Gets the registered validators as a list.
 java.lang.String getValue()
          Gets current value for a form component.
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()
          Gets the request parameters for this component as strings.
 void invalid()
          Called to indicate that
 boolean isPersistent()
           
 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 onInvalid()
          Handle invalidation by storing the user input for form repopulation
protected  void onModelChanged()
          Called anytime a model is changed after the change has occurred
protected  void onValid()
          Handle validation
 void setModelValue(java.lang.String value)
          Sets the value for a form component.
 void setPersistent(boolean persistent)
          Sets whether this component is to be persisted.
protected  boolean supportsPersistence()
           
protected abstract  void updateModel()
          Implemented by form component subclass to update the form component's model.
 void valid()
          Called to indicate that
protected  void validate()
          Validates this component using the component's validator.
 
Methods inherited from class wicket.markup.html.WebMarkupContainer
getMarkupType, onRender
 
Methods inherited from class wicket.MarkupContainer
add, autoAdd, contains, findMarkupStream, get, getMarkupStream, internalAdd, internalBeginRequest, internalEndRequest, iterator, onComponentTagBody, remove, removeAll, renderAssociatedMarkup, renderComponentTagBody, replace, setMarkupStream, setModel, size, toString, toString, visitChildren, visitChildren
 
Methods inherited from class wicket.Component
add, addStateChange, checkComponentTag, checkComponentTagAttribute, debug, detachModel, error, exceptionMessage, fatal, findPage, findParent, findParentWithAssociatedMarkup, getApplication, getApplicationPages, getApplicationSettings, getClassRelativePath, getConverter, getEscapeModelStrings, getFeedbackMessage, getFlag, getId, getLocale, getLocalizer, getModel, getModelObject, getModelObjectAsString, getPage, getPageFactory, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResource, getResponse, getSession, getString, getString, getString, getStyle, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnBeginRequest, internalOnEndRequest, internalOnModelChanged, internalOnModelChanging, isAncestorOf, isVersioned, isVisible, isVisibleInHierarchy, modelChanged, modelChanging, newPage, newPage, onBeginRequest, onEndRequest, onModelChanging, onSessionAttach, redirectTo, remove, render, renderComponent, renderComponentTag, rendered, replaceComponentTagBody, sameRootModel, sameRootModel, setFlag, setModelObject, setRedirect, setRenderBodyOnly, setResponsePage, setShouldEscapeModelStrings, setVersioned, setVisible, urlFor, visitParents, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_INVALID_INPUT

protected static final java.lang.String NO_INVALID_INPUT
Special flag value to indicate when there is no invalid input, since null is a valid value!

See Also:
Constant Field Values

FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL

protected static final short FLAG_CONVERT_EMPTY_INPUT_STRING_TO_NULL
Make empty strings null values boolean

See Also:
Constant Field Values
Constructor Detail

FormComponent

public FormComponent(java.lang.String id)
See Also:
Component.Component(String)

FormComponent

public FormComponent(java.lang.String id,
                     IModel model)
See Also:
Component.Component(String, IModel)
Method Detail

add

public final FormComponent add(IValidator validator)
Adds a validator to this form component.

Parameters:
validator - The validator
Returns:
This

getForm

public final Form getForm()
Returns:
The parent form for this form component

getInput

public final java.lang.String getInput()
Gets the request parameter for this component as a string.

Returns:
The value in the request for this component

getValidationType

public final java.lang.Class getValidationType()
Gets the type for any TypeValidator assigned to this component.

Returns:
Any type assigned to this component via type validation, or null if no TypeValidator has been added.

getValidators

public final java.util.List getValidators()
Gets the registered validators as a list.

Returns:
the validators as a list

getValue

public final java.lang.String getValue()
Gets current value for a form component.

Returns:
The value

invalid

public final void invalid()
Called to indicate that


isPersistent

public final boolean isPersistent()
Returns:
True if this component supports persistence AND it has been asked to persist itself with setPersistent().

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 nescesarry as we don't want the form component models updated with invalid input.

Returns:
valid whether this component is 'valid'

isValidated

public final boolean isValidated()
Gets whether this component is to be validated.

Returns:
True if this component has one or more validators

setModelValue

public void setModelValue(java.lang.String value)
Sets the value for a form component.

Parameters:
value - The value

setPersistent

public final void setPersistent(boolean persistent)
Sets whether this component is to be persisted.

Parameters:
persistent - True if this component is to be persisted.

valid

public final void valid()
Called to indicate that


getModelValue

protected java.lang.String getModelValue()
Returns:
Value to return when model value is needed

inputAsInt

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

Returns:
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.

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

inputAsIntArray

protected final int[] inputAsIntArray()
Gets the request parameters for this component as ints.

Returns:
The values in the request for this component

inputAsStringArray

protected final java.lang.String[] inputAsStringArray()
Gets the request parameters for this component as strings.

Returns:
The valuess in the request for this component

onComponentTag

protected void onComponentTag(ComponentTag tag)
Processes the component tag.

Overrides:
onComponentTag in class Component
Parameters:
tag - Tag to modify
See Also:
Component.onComponentTag(ComponentTag)

onInvalid

protected void onInvalid()
Handle invalidation by storing the user input for form repopulation


onModelChanged

protected void onModelChanged()
Description copied from class: Component
Called anytime a model is changed after the change has occurred

Overrides:
onModelChanged in class Component
See Also:
Component.onModelChanged()

onValid

protected void onValid()
Handle validation


supportsPersistence

protected boolean supportsPersistence()
Returns:
True if this type of FormComponent can be persisted.

updateModel

protected abstract void updateModel()
Implemented by form component subclass to update the form component's model.


validate

protected final void validate()
Validates this component using the component's validator.



Copyright © 2004-2005 Wicket developers. All Rights Reserved.