wheel.components
Class FormElement

java.lang.Object
  extended by wheel.components.Component
      extended by wheel.components.RenderableComponent
          extended by wheel.components.FormElement
Direct Known Subclasses:
Checkbox, DateInput, FileInput, Hidden, NumberInput, Radio, SelectModelFormElement, Submit, TextArea, TextInput

public abstract class FormElement
extends RenderableComponent

All components that want to handle form input should extend from this class. Defines a set of operations like validation and binding.
Binding fields to FormElements:
Binding is done with MVEL-expressions. The only rule is that the target of the binding must be available in the complex component using javabean get/set-methods.
Example:

 public class MyComponent extends StandaloneComponent {
  private Calendar cal;

  public Calendar getCal() {
      return cal;
  }

  public void setCal(Calendar cal) {
      this.cal = cal;
  }
 }
 
In the above example, the containing complex component has a field declaration like this:
private List numbers;
Note that when using Lists and Maps, they need to be initialized, ie. they can't be empty. Limitations:
Array types are not supported at the moment. Use Collections-api instead.

Author:
Henri Frilund

Field Summary
protected  java.lang.String genericFieldErrorMessage
           
protected  java.lang.String[] value
           
 
Constructor Summary
protected FormElement(Component parent, java.lang.String formElementName)
           
 
Method Summary
 void _clear()
          Inteded for internal use.
 java.lang.String _getSubmitValue()
          Returns the value recieved in form submit.
 java.lang.String[] _getSubmitValues()
          Returns the value recieved in form submit.
 void _render(org.xmlpull.v1.XmlSerializer serializer)
          Default implementation.
 void _setSubmitValue(java.lang.String[] value)
          Sets the value retrieved from a form submit for this element.
 FormElement addValidationError(java.lang.String message)
           
protected  java.lang.String defaultDomEvent()
           
 FormElement fieldBinding(java.lang.String binding)
           
 java.lang.CharSequence getBinding()
          Returns the binding for this form element.
 java.util.List<ValidationError> getErrors()
          Returns all validation errors for this form element.
 java.lang.String getFormElementName()
           
 FormElement initialFieldValue(java.lang.String value)
           
 FormElement initialFieldValue(java.lang.String value, java.lang.Object emptyValue)
           
 boolean isEmpty()
          Returns true if no value has been set due to a form submit to this element yet.
 FormElement isInt()
          A shorthand method to mark this form element as an integer.
 boolean isValid()
          Returns true if this form element is valid.
 FormElement label(java.lang.String label)
          Adds a label to this form element.
 FormElement required()
          A shorthand method to mark this form element as required.
 FormElement setBinding(java.lang.CharSequence binding)
           
 FormElement setFormElementName(java.lang.String name)
           
 void validate()
          Causes this element to validate itself against given input value.
 FormElement validationRule(java.lang.String elExpression)
           
 FormElement validationRule(java.lang.String elExpression, java.lang.String message)
          Adds a validation rule to this form element.
 FormElement value(java.lang.String value)
           
 
Methods inherited from class wheel.components.RenderableComponent
_classReferenceFromHints, _getRenderAfterMe, _getRenderBeforeMe, _renderActions, _renderClassReferenceFromHints, _renderTagStart, _renderXhtmlAttributes, addRenderAfter, addRenderBefore, config, defaultTagName, getTagName, renderComponent, toString
 
Methods inherited from class wheel.components.Component
_applyFormat, _getAction, _getActions, _getChildren, _getForm, _getRenderableChildren, _getRenderHints, _getTopLevelComponent, _getVisibleForm, _getXhtmlAttributes, _isGeneratedId, _setComponentId, _setGeneratedId, _wrapComponentId, a, a, abbr, abbr, acronym, acronym, action, actionBinding, actionBinding, add, addFirst, address, address, afterAdd, area, attribute, attributes, b, b, base, bdo, big, big, blockquote, br, button, caption, checkbox, checkboxGroup, cite, cite, clasS, col, colgroup, create, dateInput, dd, dd, del, del, dfn, dfn, div, dl, dt, dt, el, em, em, encode, entity, equals, eval, fieldset, fileInput, fileInput, find, findAll, form, form, frame, frameset, get, getComponentId, getComponentName, getComponents, getEngine, getPage, getParent, h1, h1, h2, h2, h3, h3, h4, h4, h5, h5, h6, h6, hashCode, head, hidden, hr, htmlText, i, i, id, iframe, img, ins, ins, kbd, kdb, label, label, legend, legend, li, li, link, link, map, message, message, meta, multiSelect, nbsp, noframes, noscript, numberInput, numberInput, object, ol, p, p, param, placeholder, pre, pre, q, q, radio, radioGroup, rawText, remove, remove, renderHint, requestFocus, s, s, samp, samp, script, select, selectModel, small, small, span, span, strike, strike, strong, strong, style, sub, sub, submit, sup, sup, table, tbody, td, text, textarea, textInput, tfoot, th, thead, title, tr, u, u, ul, up, up, var, var, wBlock, wrapSelf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected java.lang.String[] value

genericFieldErrorMessage

protected java.lang.String genericFieldErrorMessage
Constructor Detail

FormElement

protected FormElement(Component parent,
                      java.lang.String formElementName)
Method Detail

validationRule

public FormElement validationRule(java.lang.String elExpression,
                                  java.lang.String message)
Adds a validation rule to this form element. Validation rules are MVEL-expressions that are beefed up with a set of predefined variables and a set of validation methods as a default context. Example:
A validation expression "isInt(value)" is equivalent to Validations.getInstance().isInt(formElement.getValue);
Predefined variables:
  1. value - the submitted form value for this field.
  2. element - a reference to this, ie. gives access to the form element itself.
  3. form - a reference to the Form-component that contains the form element.

Additional variables can be injected using StandaloneComponent.config().useValidationVariable() method.

Parameters:
elExpression - A valid MVEL-expression
message - The message to put in the ValidationError object if the validation fails. Can be an el-expression or a localized message.
Returns:
See Also:
Validations for currently avaiable validation methods.

validationRule

public FormElement validationRule(java.lang.String elExpression)

getBinding

public java.lang.CharSequence getBinding()
Returns the binding for this form element.

Returns:

setBinding

public FormElement setBinding(java.lang.CharSequence binding)

isEmpty

public boolean isEmpty()
Returns true if no value has been set due to a form submit to this element yet.

Returns:

validate

public void validate()
Causes this element to validate itself against given input value.


_setSubmitValue

public void _setSubmitValue(java.lang.String[] value)
Sets the value retrieved from a form submit for this element. Calling this method also triggers a call to validate();

Parameters:
value -

label

public FormElement label(java.lang.String label)
Adds a label to this form element. Will create a <label for="componentId">label text</label> tag before the form element.

Parameters:
label - The text to render inside the label-tag.
Returns:

getErrors

public java.util.List<ValidationError> getErrors()
Returns all validation errors for this form element.

Returns:

isValid

public boolean isValid()
Returns true if this form element is valid.

Returns:

_getSubmitValues

public java.lang.String[] _getSubmitValues()
Returns the value recieved in form submit.

Returns:

_getSubmitValue

public java.lang.String _getSubmitValue()
Returns the value recieved in form submit.

Returns:

_clear

public void _clear()
Description copied from class: Component
Inteded for internal use. Clears all attributes and child components.

Overrides:
_clear in class RenderableComponent

required

public FormElement required()
A shorthand method to mark this form element as required.

Returns:

isInt

public FormElement isInt()
A shorthand method to mark this form element as an integer.

Returns:

defaultDomEvent

protected java.lang.String defaultDomEvent()
Overrides:
defaultDomEvent in class RenderableComponent

setFormElementName

public FormElement setFormElementName(java.lang.String name)

getFormElementName

public java.lang.String getFormElementName()

_render

public void _render(org.xmlpull.v1.XmlSerializer serializer)
             throws java.io.IOException
Description copied from class: RenderableComponent
Default implementation. Handles render before/after logic. Will first figure out the xhtml tag to use from rendering hints, then delegates to renderComponent(). Subclasses should override renderComponent() rather than this method.

Overrides:
_render in class RenderableComponent
Throws:
java.io.IOException

fieldBinding

public FormElement fieldBinding(java.lang.String binding)

value

public FormElement value(java.lang.String value)

initialFieldValue

public FormElement initialFieldValue(java.lang.String value)

initialFieldValue

public FormElement initialFieldValue(java.lang.String value,
                                     java.lang.Object emptyValue)

addValidationError

public FormElement addValidationError(java.lang.String message)


Copyright © 2007-2008. All Rights Reserved.