org.barracudamvc.core.forms
Class DefaultFormElement

java.lang.Object
  extended by org.barracudamvc.core.forms.DefaultFormElement
All Implemented Interfaces:
Comparable, FormElement
Direct Known Subclasses:
CheckboxFormElement, SelectFormElement, TextAreaFormElement, UploadElement, UploadLinkElement

public class DefaultFormElement
extends Object
implements FormElement

A FormElement defines how an element in a FormMap should be mapped to a first class java object. There are several key pieces of information required:

Once we have this information, we basically have enough data to map a String value in the data source to a first class Java object in the element.

Note that the element keeps track of the original value as well, so that if for some reason you ever need to get to it that information is available.

Also not that we provide convenience methods which automatically cast for you (Note however: this type of thing is not type safe, meaning that you can get a ClassCastException if you do a getXXXVal() when the underlying object is not of type XXX.


Field Summary
protected  boolean allowMultiples
           
protected  Object defaultVal
           
protected  Format format
           
protected  String key
           
protected static org.apache.log4j.Logger logger
           
protected  String name
           
protected  Object origVal
           
protected  FormMap parent
           
protected  ParseException pe
           
protected  FormType type
           
protected  Object val
           
protected  FormValidator validator
           
 
Constructor Summary
DefaultFormElement()
          Public noargs constructor.
DefaultFormElement(FormElement feSource)
          Public constructor
DefaultFormElement(String ikey)
          Public constructor.
DefaultFormElement(String ikey, FormType itype)
          Public constructor.
DefaultFormElement(String ikey, FormType itype, Object idefaultVal)
          Public constructor.
DefaultFormElement(String ikey, FormType itype, Object idefaultVal, FormValidator ivalidator)
          Public constructor.
DefaultFormElement(String ikey, FormType itype, Object idefaultVal, FormValidator ivalidator, boolean iallowMultiples)
          Public constructor, Name defaults to Key
DefaultFormElement(String ikey, String iname, FormType itype, Object idefaultVal, FormValidator ivalidator, boolean iallowMultiples)
          Public constructor
 
Method Summary
 boolean allowMultiples()
          Does this element allow multiple values
 int compareTo(Object o)
          Compares with another object to determine ordering
 Object getDefaultVal()
          Get the default value for this form element
 Format getFormat()
          Set the Format object for this element (null indicates default formatting)
 String getKey()
          Get the key value for this form element
 String getName()
          Get the name of this form element
 Object getOrigVal()
          Get the original value for this element
 FormMap getParentForm()
          Get the parent form map
 ParseException getParseException()
          Get any parse exceptions associated with the element (ie. that might have occurred when the element was mapped)
 FormType getType()
          Get the FormType for this for element
 Object getVal()
          Get the value for this element.
 Object getVal(Object dflt)
           
 FormValidator getValidator()
          Get the default FormValidator for this form element
 Object[] getVals()
          Get all the values for this element.
 Object[] getVals(Object[] dflt)
           
 FormElement setAllowMultiples(boolean val)
          Set whether or not this element allows multiple values
 FormElement setDefaultVal(Object idefaultVal)
          Set the default value for this form element
 FormElement setFormat(Format iformat)
          Set the Format object for this element (null indicates default formatting)
 FormElement setKey(String ikey)
          Set the key value for this form element
 FormElement setName(String iname)
          Set the name of this form element
 FormElement setOrigVal(Object iorigVal)
          Set the original value for this element
 FormElement setParentForm(FormMap iparent)
          Set the parent form map
 FormElement setParseException(ParseException ipe)
          Set the parse exception associated with this element
 FormElement setType(FormType itype)
          Set the FormType for this form element
 FormElement setVal(Object ival)
          Set the value for this element
 FormElement setValidator(FormValidator ivalidator)
          Set the FormValidator for this form element
 String toString()
          Get a string representation of this element
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

parent

protected FormMap parent

key

protected String key

name

protected String name

type

protected FormType type

defaultVal

protected Object defaultVal

pe

protected ParseException pe

validator

protected FormValidator validator

allowMultiples

protected boolean allowMultiples

origVal

protected Object origVal

val

protected Object val

format

protected Format format
Constructor Detail

DefaultFormElement

public DefaultFormElement()
Public noargs constructor. Form key defaults to null.


DefaultFormElement

public DefaultFormElement(String ikey)
Public constructor. Form type defaults to FormType.STRING

Parameters:
ikey - the key name in the data source

DefaultFormElement

public DefaultFormElement(String ikey,
                          FormType itype)
Public constructor. Default value defaults to Null.

Parameters:
ikey - the key name in the data source
itype - the FormType for the element

DefaultFormElement

public DefaultFormElement(String ikey,
                          FormType itype,
                          Object idefaultVal)
Public constructor. Validator defaults to null.

Parameters:
ikey - the key name in the data source
itype - the FormType for the element
idefaultVal - the default value to be used if the key is not found in the data source or the value for the key is null

DefaultFormElement

public DefaultFormElement(String ikey,
                          FormType itype,
                          Object idefaultVal,
                          FormValidator ivalidator)
Public constructor. AllowMultiples defaults to false.

Parameters:
ikey - the key name in the data source
itype - the FormType for the element
idefaultVal - the default value to be used if the key is not found in the data source or the value for the key is null
ivalidator - the FormValidator associated with this element

DefaultFormElement

public DefaultFormElement(String ikey,
                          FormType itype,
                          Object idefaultVal,
                          FormValidator ivalidator,
                          boolean iallowMultiples)
Public constructor, Name defaults to Key

Parameters:
ikey - the key name in the data source
itype - the FormType for the element
idefaultVal - the default value to be used if the key is not found in the data source or the value for the key is null
ivalidator - the FormValidator associated with this element
iallowMultiples - true if there may be multiple values in the datasource for this particular key name

DefaultFormElement

public DefaultFormElement(String ikey,
                          String iname,
                          FormType itype,
                          Object idefaultVal,
                          FormValidator ivalidator,
                          boolean iallowMultiples)
Public constructor

Parameters:
ikey - the key name in the data source
iname - the name for the element
itype - the FormType for the element
idefaultVal - the default value to be used if the key is not found in the data source or the value for the key is null
ivalidator - the FormValidator associated with this element
iallowMultiples - true if there may be multiple values in the datasource for this particular key name

DefaultFormElement

public DefaultFormElement(FormElement feSource)
Public constructor

Parameters:
feSource - the form element on which to base this form element
Method Detail

setKey

public FormElement setKey(String ikey)
Set the key value for this form element

Specified by:
setKey in interface FormElement
Parameters:
ikey - the key value for this form element
Returns:
a reference to the current form element

getKey

public String getKey()
Get the key value for this form element

Specified by:
getKey in interface FormElement
Returns:
the key for this form element

setName

public FormElement setName(String iname)
Set the name of this form element

Specified by:
setName in interface FormElement
Parameters:
iname - the name of this form element
Returns:
a reference to the current form element

getName

public String getName()
Get the name of this form element

Specified by:
getName in interface FormElement
Returns:
the name of this form element

setType

public FormElement setType(FormType itype)
Set the FormType for this form element

Specified by:
setType in interface FormElement
Parameters:
itype - the FormType for this form element
Returns:
a reference to the current form element

getType

public FormType getType()
Get the FormType for this for element

Specified by:
getType in interface FormElement
Returns:
the FormType for this form element

setDefaultVal

public FormElement setDefaultVal(Object idefaultVal)
Set the default value for this form element

Specified by:
setDefaultVal in interface FormElement
Parameters:
idefaultVal - the FormType for this form element
Returns:
a reference to the current form element

getDefaultVal

public Object getDefaultVal()
Get the default value for this form element

Specified by:
getDefaultVal in interface FormElement
Returns:
the default value for this form element (may be null)

setAllowMultiples

public FormElement setAllowMultiples(boolean val)
Set whether or not this element allows multiple values

Specified by:
setAllowMultiples in interface FormElement
Parameters:
val - true if the element allows multiples
Returns:
a reference to the current form element

allowMultiples

public boolean allowMultiples()
Does this element allow multiple values

Specified by:
allowMultiples in interface FormElement
Returns:
true if this element allows multiple values

setValidator

public FormElement setValidator(FormValidator ivalidator)
Set the FormValidator for this form element

Specified by:
setValidator in interface FormElement
Parameters:
ivalidator - the FormValidator for this form element
Returns:
a reference to the current form element

getValidator

public FormValidator getValidator()
Get the default FormValidator for this form element

Specified by:
getValidator in interface FormElement
Returns:
the validator for this form element (may be null)

setOrigVal

public FormElement setOrigVal(Object iorigVal)
Set the original value for this element

Specified by:
setOrigVal in interface FormElement
Parameters:
iorigVal - the original value
Returns:
a reference to the current form element

getOrigVal

public Object getOrigVal()
Get the original value for this element

Specified by:
getOrigVal in interface FormElement
Returns:
the original value for this form element (may be null)

setVal

public FormElement setVal(Object ival)
Set the value for this element

Specified by:
setVal in interface FormElement
Parameters:
ival - the value for this element
Returns:
a reference to the current form element

getVal

public Object getVal()
Get the value for this element. If the underlying object is actually an array (ie. allowMultiples = true), then you should really be calling getVals() to get the whole object array; if you call this method, you will just get the first element of the array.

Specified by:
getVal in interface FormElement
Returns:
the value for this form element (may be null)

getVal

public Object getVal(Object dflt)
Specified by:
getVal in interface FormElement

getVals

public Object[] getVals()
Get all the values for this element. There will always be an array returned. if the value for this FormElement is null, an empty array is returned. This method only really makes sense if allowMultiples = true

Specified by:
getVals in interface FormElement
Returns:
the array of values for this form element

getVals

public Object[] getVals(Object[] dflt)
Specified by:
getVals in interface FormElement

setParseException

public FormElement setParseException(ParseException ipe)
Set the parse exception associated with this element

Specified by:
setParseException in interface FormElement
Returns:
any parse exceptions associated with the element

getParseException

public ParseException getParseException()
Get any parse exceptions associated with the element (ie. that might have occurred when the element was mapped)

Specified by:
getParseException in interface FormElement
Returns:
any parse exceptions associated with the element

setFormat

public FormElement setFormat(Format iformat)
Set the Format object for this element (null indicates default formatting)

Specified by:
setFormat in interface FormElement
Parameters:
iformat - the Format for this form element
Returns:
a reference to the current form element

getFormat

public Format getFormat()
Set the Format object for this element (null indicates default formatting)

Specified by:
getFormat in interface FormElement
Returns:
the Format for this form element

setParentForm

public FormElement setParentForm(FormMap iparent)
Set the parent form map

Specified by:
setParentForm in interface FormElement
Parameters:
iparent - the parent map object
Returns:
a reference to the current form element

getParentForm

public FormMap getParentForm()
Get the parent form map

Specified by:
getParentForm in interface FormElement

compareTo

public int compareTo(Object o)
Compares with another object to determine ordering

Specified by:
compareTo in interface Comparable

toString

public String toString()
Get a string representation of this element

Overrides:
toString in class Object
Returns:
the String describing this element


Copyright © 2006 BarracudaMVC.org All Rights Reserved.