org.enhydra.barracuda.core.forms
Class DefaultFormElement

java.lang.Object
  extended byorg.enhydra.barracuda.core.forms.DefaultFormElement
All Implemented Interfaces:
FormElement
Direct Known Subclasses:
CheckboxFormElement, SelectFormElement, TextAreaFormElement

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  String key
           
protected static org.apache.log4j.Logger logger
           
protected  String name
           
protected  Object origVal
           
protected  ParseException pe
           
protected  FormType type
           
protected  Object val
           
protected  FormValidator validator
           
 
Constructor Summary
DefaultFormElement()
          Public noargs 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
 Boolean getBooleanVal()
          Get the value for this element as a Boolean
 Boolean getBooleanVal(Boolean dflt)
          Get a Boolean value from the map, defaulting accordingly if the value is null
 Date getDateVal()
          Get the value for this element as a Date
 Date getDateVal(Date dflt)
          Get a Date value from the map, defaulting accordingly if the value is null
 Object getDefaultVal()
          Get the default value for this form element
 Double getDoubleVal()
          Get the value for this element as a Double
 Double getDoubleVal(Double dflt)
          Get a Double value from the map, defaulting accordingly if the value is null
 Float getFloatVal()
          Get the value for this element as a Float
 Float getFloatVal(Float dflt)
          Get a Float value from the map, defaulting accordingly if the value is null
 Integer getIntegerVal()
          Get the value for this element as a Integer
 Integer getIntegerVal(Integer dflt)
          Get a Integer value from the map, defaulting accordingly if the value is null
 String getKey()
          Get the key value for this form element
 Long getLongVal()
          Get the value for this element as a Long
 Long getLongVal(Long dflt)
          Get a Long value from the map, defaulting accordingly if the value is null
 String getName()
          Get the name of this form element
 Object getOrigVal()
          Get the original value for this element
 ParseException getParseException()
          Get any parse exceptions associated with the element (ie. that might have occurred when the element was mapped)
 Short getShortVal()
          Get the value for this element as a Short
 Short getShortVal(Short dflt)
          Get a Short value from the map, defaulting accordingly if the value is null
 String getStringVal()
          Get the value for this element as a String
 String getStringVal(String dflt)
          Get the value for this element as a String, defaulting accordingly if the value is null
 FormType getType()
          Get the FormType for this for element
 Object getVal()
          Get the value for this element.
 FormValidator getValidator()
          Get the default FormValidator for this form element
 Object[] getVals()
          Get all the values for this element.
 void setAllowMultiples(boolean val)
          Set whether or not this element allows multiple values
 void setDefaultVal(Object idefaultVal)
          Set the default value for this form element
 void setKey(String ikey)
          Set the key value for this form element
 void setName(String iname)
          Set the name of this form element
 void setOrigVal(Object iorigVal)
          Set the original value for this element
 void setParseException(ParseException ipe)
          Set the parse exception associated with this element
 void setType(FormType itype)
          Set the FormType for this form element
 void setVal(Object ival)
          Set the value for this element
 void 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

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
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
Method Detail

setKey

public void 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

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 void setName(String iname)
Set the name of this form element

Specified by:
setName in interface FormElement
Parameters:
iname - the name of this 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 void setType(FormType itype)
Set the FormType for this form element

Specified by:
setType in interface FormElement
Parameters:
itype - the FormType for this 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 void 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

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 void 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

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 void setValidator(FormValidator ivalidator)
Set the FormValidator for this form element

Specified by:
setValidator in interface FormElement
Parameters:
ivalidator - the FormValidator for this 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 void setOrigVal(Object iorigVal)
Set the original value for this element

Specified by:
setOrigVal in interface FormElement
Parameters:
iorigVal - the original value

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 void setVal(Object ival)
Set the value for this element

Specified by:
setVal in interface FormElement
Parameters:
ival - the value for this 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)

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

getStringVal

public String getStringVal()
Get the value for this element as a String

Specified by:
getStringVal in interface FormElement

getStringVal

public String getStringVal(String dflt)
Get the value for this element as a String, defaulting accordingly if the value is null

Specified by:
getStringVal in interface FormElement

getBooleanVal

public Boolean getBooleanVal()
Get the value for this element as a Boolean

Specified by:
getBooleanVal in interface FormElement

getBooleanVal

public Boolean getBooleanVal(Boolean dflt)
Get a Boolean value from the map, defaulting accordingly if the value is null

Specified by:
getBooleanVal in interface FormElement

getIntegerVal

public Integer getIntegerVal()
Get the value for this element as a Integer

Specified by:
getIntegerVal in interface FormElement

getIntegerVal

public Integer getIntegerVal(Integer dflt)
Get a Integer value from the map, defaulting accordingly if the value is null

Specified by:
getIntegerVal in interface FormElement

getDateVal

public Date getDateVal()
Get the value for this element as a Date

Specified by:
getDateVal in interface FormElement

getDateVal

public Date getDateVal(Date dflt)
Get a Date value from the map, defaulting accordingly if the value is null

Specified by:
getDateVal in interface FormElement

getLongVal

public Long getLongVal()
Get the value for this element as a Long

Specified by:
getLongVal in interface FormElement

getLongVal

public Long getLongVal(Long dflt)
Get a Long value from the map, defaulting accordingly if the value is null

Specified by:
getLongVal in interface FormElement

getShortVal

public Short getShortVal()
Get the value for this element as a Short

Specified by:
getShortVal in interface FormElement

getShortVal

public Short getShortVal(Short dflt)
Get a Short value from the map, defaulting accordingly if the value is null

Specified by:
getShortVal in interface FormElement

getDoubleVal

public Double getDoubleVal()
Get the value for this element as a Double

Specified by:
getDoubleVal in interface FormElement

getDoubleVal

public Double getDoubleVal(Double dflt)
Get a Double value from the map, defaulting accordingly if the value is null

Specified by:
getDoubleVal in interface FormElement

getFloatVal

public Float getFloatVal()
Get the value for this element as a Float

Specified by:
getFloatVal in interface FormElement

getFloatVal

public Float getFloatVal(Float dflt)
Get a Float value from the map, defaulting accordingly if the value is null

Specified by:
getFloatVal in interface FormElement

setParseException

public void 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

toString

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

Returns:
the String describing this element


Copyright © 2003 BarracudaMVC.org All Rights Reserved.