adapforms.form.elements
Class ValueHoldingElement

java.lang.Object
  extended by adapforms.form.elements.FormElement
      extended by adapforms.form.elements.ValueHoldingElement
Direct Known Subclasses:
ChoiceElement, DateElement, DecimalElement, IntegerElement, LabelElement, TextElement, ToggleElement

public abstract class ValueHoldingElement
extends FormElement

Form element capable of holding one or more values. Examples include text fields, lists etc.

Author:
Henrik Gammelmark, geemark@cs.au.dk

Constructor Summary
protected ValueHoldingElement(java.lang.String id, SimpleLabel label)
           
 
Method Summary
protected  ValidationProblem buildError(java.lang.String err)
          Utility method used by subclasses to construct a validation problem instance.
protected  java.util.List<ValidationProblem> buildSingleError(java.lang.String err)
          Utility method used by subclasses to construct a single validation problem instance and wrap it in a single-itemlist.
protected  void cloneFinalize(ValueHoldingElement clone)
          When cloning a value-holding element, use this method to clone all common superclass parameters.
abstract  java.lang.Object convertValue(java.lang.Object rawValue, Localization localization)
          Given a raw input value, perform relevant conversions, so that the type integrity is preserved.
abstract  java.lang.Object getInitialValue()
          Get the value this element should be initialized with when the element is instantiated in the form instance.
 java.lang.String[] getRolesWrite()
          List of user roles allowed to change the value held in this element.
 java.util.List<ValidationRule> getValidationRules()
          Get the validation rules associated with this element.
 boolean isEmptyValue(java.lang.Object value)
          Given a value (possibly null), determine if the value is considered to be an "empty" value.
 BooleanExpression isReadOnly()
          Is the user allowed to change the value held in this element?
 BooleanExpression isRequired()
          Is the user required to enter a value into this element?
abstract  java.lang.String marshallValue(java.lang.Object value)
          Given a value of the expected type, convert it to a string representation.
 void setReadOnly(BooleanExpression value)
          See isReadOnly().
 void setRequired(BooleanExpression value)
          See isRequired().
 void setRolesWrite(java.lang.String[] write)
          See getRolesWrite().
 void setValidationRules(java.util.List<ValidationRule> rules)
          Set the validation rules associated with this element.
protected  java.lang.String toStringHelper(java.lang.String append)
          Helper method for FormElement.toString() in subclasses.
 java.util.List<ValidationProblem> validateValue(java.lang.Object value, Localization localization)
          Given a converted (see convertValue(java.lang.Object, adapforms.runtime.i18n.Localization)) value, check if it is valid.
 
Methods inherited from class adapforms.form.elements.FormElement
clone, cloneFinalize, getElementID, getLabel, getRolesRead, getUIFlags, isRelevant, setRelevant, setRolesRead, setUIFlags, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValueHoldingElement

protected ValueHoldingElement(java.lang.String id,
                              SimpleLabel label)
Method Detail

isRequired

public final BooleanExpression isRequired()
Is the user required to enter a value into this element?


isReadOnly

public final BooleanExpression isReadOnly()
Is the user allowed to change the value held in this element?


getRolesWrite

public final java.lang.String[] getRolesWrite()
List of user roles allowed to change the value held in this element.


setRolesWrite

public final void setRolesWrite(java.lang.String[] write)
See getRolesWrite().


setRequired

public final void setRequired(BooleanExpression value)
See isRequired().


setReadOnly

public final void setReadOnly(BooleanExpression value)
See isReadOnly().


isEmptyValue

public boolean isEmptyValue(java.lang.Object value)
Given a value (possibly null), determine if the value is considered to be an "empty" value. Used (among other things) to check if a given value satisfied the "required" requirement (see isRequired()).


convertValue

public abstract java.lang.Object convertValue(java.lang.Object rawValue,
                                              Localization localization)
                                       throws TypeException
Given a raw input value, perform relevant conversions, so that the type integrity is preserved.

Parameters:
rawValue - Value to convert
localization - Localization to use, when generating problem messages
Throws:
TypeException - If the value cannot be converted

marshallValue

public abstract java.lang.String marshallValue(java.lang.Object value)
                                        throws TypeException
Given a value of the expected type, convert it to a string representation.

Parameters:
value - Value to marshall
Returns:
String representation
Throws:
TypeException - If the given value is not recognized

validateValue

public java.util.List<ValidationProblem> validateValue(java.lang.Object value,
                                                       Localization localization)
Given a converted (see convertValue(java.lang.Object, adapforms.runtime.i18n.Localization)) value, check if it is valid. This enables the element to perform simple validation.

Parameters:
value - Value to validate
localization - Localization to use, when generating problem messages
Returns:
null or empty list if ok, problem list otherwise.

buildError

protected ValidationProblem buildError(java.lang.String err)
Utility method used by subclasses to construct a validation problem instance.

Parameters:
err - if null, null is returned. Otherwise, a ValidationProblem with the given message is returned.

buildSingleError

protected java.util.List<ValidationProblem> buildSingleError(java.lang.String err)
Utility method used by subclasses to construct a single validation problem instance and wrap it in a single-itemlist.

Parameters:
err - Problem message
Returns:
Problem wrapped in list

cloneFinalize

protected void cloneFinalize(ValueHoldingElement clone)
When cloning a value-holding element, use this method to clone all common superclass parameters.

Parameters:
clone - The clone
See Also:
FormElement.clone(String, SimpleLabel)

setValidationRules

public void setValidationRules(java.util.List<ValidationRule> rules)
Set the validation rules associated with this element. Should be the empty list if none.


getValidationRules

public java.util.List<ValidationRule> getValidationRules()
Get the validation rules associated with this element. If none, the empty list is returned.


getInitialValue

public abstract java.lang.Object getInitialValue()
Get the value this element should be initialized with when the element is instantiated in the form instance.

Returns:
Value to set, or null to set no initial value

toStringHelper

protected java.lang.String toStringHelper(java.lang.String append)
Description copied from class: FormElement
Helper method for FormElement.toString() in subclasses.

Overrides:
toStringHelper in class FormElement