Class DefaultFieldHandler
- java.lang.Object
-
- net.sf.jguiraffe.gui.forms.DefaultFieldHandler
-
- All Implemented Interfaces:
FieldHandler
public class DefaultFieldHandler extends Object implements FieldHandler
A default implementation of the
FieldHandlerinterface.This class implements all necessary functionality to deal with form fields of different types. It supports both validation and conversion of data. Conversion works in two directions: from a bean property to a representation that can be processed by a GUI widget and vice versa. Validation (on the field and form level) ensures that data entered by the user is syntactically and semantically valid.
To perform its tasks this class makes use of some
ValidatorandTransformerobjects that can be associated with an instance. It ensures that the services provided by these objects are accessed when necessary. When creating an instance of this class it must be ensured that the correct validators and transformers are set; especially the data types they operate on must be compatible.- Version:
- $Id: DefaultFieldHandler.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description DefaultFieldHandler()Creates a new instance ofDefaultFieldHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ObjectfetchFieldData()Fetches the form field's data directly from the component handler.ComponentHandler<?>getComponentHandler()Returns the component handler.ObjectgetData()Fetches the data of this field.StringgetDisplayName()Returns the display name.ValidatorWrappergetLogicValidator()Returns the validator used for validation on the logic level.StringgetPropertyName()Returns the property name of this field if one is set.TransformerWrappergetReadTransformer()Returns the read transformer.ValidatorWrappergetSyntaxValidator()Returns the validator used for validation on the syntax level.Class<?>getType()Returns the data type of this field.TransformerWrappergetWriteTransformer()Returns the write transformer.voidsetComponentHandler(ComponentHandler<?> componentHandler)Sets the component handler.voidsetData(Object data)Sets the data for this field.voidsetDisplayName(String displayName)Sets the display name.voidsetLogicValidator(ValidatorWrapper formValidator)Sets the validator used for validation on the logic level.voidsetPropertyName(String n)Sets the property name of this field.voidsetReadTransformer(TransformerWrapper readTransformer)Sets the read transformer.voidsetSyntaxValidator(ValidatorWrapper fieldValidator)Sets the validator used for validation on the syntax level.voidsetType(Class<?> type)Sets the data type for this form field.voidsetWriteTransformer(TransformerWrapper writeTransformer)Sets the write transformer.ValidationResultvalidate(ValidationPhase phase)Performs validation for the specified phase and returns the results.protected ValidationResultvalidateFieldData(Object data)Performs a form level validation of this field.protected ValidationResultvalidateFieldLevel()Performs validation on the field level.protected ValidationResultvalidateFormLevel()Performs validation on the form level.
-
-
-
Method Detail
-
getSyntaxValidator
public ValidatorWrapper getSyntaxValidator()
Returns the validator used for validation on the syntax level. If no specific validator is set, a dummy validator is used.- Returns:
- the validator on the field level
-
setSyntaxValidator
public void setSyntaxValidator(ValidatorWrapper fieldValidator)
Sets the validator used for validation on the syntax level.- Parameters:
fieldValidator- the field level validator
-
getLogicValidator
public ValidatorWrapper getLogicValidator()
Returns the validator used for validation on the logic level. If no specific validator has been set, a dummy validator is used.- Returns:
- the validator on the form level
-
setLogicValidator
public void setLogicValidator(ValidatorWrapper formValidator)
Sets the validator used for validation on the logic level.- Parameters:
formValidator- the form level validator
-
getReadTransformer
public TransformerWrapper getReadTransformer()
Returns the read transformer. If no specific transformer is set, a dummy transformer is used.- Returns:
- the read transformer
-
setReadTransformer
public void setReadTransformer(TransformerWrapper readTransformer)
Sets the read transformer. This transformer is used when reading data from the associated GUI widget. It transforms from the widget's data type to the target data type (provided that field level validation has been successful).- Parameters:
readTransformer- the read transformer
-
getWriteTransformer
public TransformerWrapper getWriteTransformer()
Returns the write transformer. If no specific write transformer has been set, a dummy transformer is used.- Returns:
- the write transformer
-
setWriteTransformer
public void setWriteTransformer(TransformerWrapper writeTransformer)
Sets the write transformer. This transformer is used when initializing the associated widget's data with form data. It transforms from the field's target data type to the widget's data type.- Parameters:
writeTransformer- the write transformer
-
getComponentHandler
public ComponentHandler<?> getComponentHandler()
Returns the component handler.- Specified by:
getComponentHandlerin interfaceFieldHandler- Returns:
- the component handler
-
setComponentHandler
public void setComponentHandler(ComponentHandler<?> componentHandler)
Sets the component handler.- Parameters:
componentHandler- the component handler
-
getType
public Class<?> getType()
Returns the data type of this field. If a type was explicitely set, this type is returned. Otherwise theComponentHandler's type is returned.- Specified by:
getTypein interfaceFieldHandler- Returns:
- the type of this field
-
setType
public void setType(Class<?> type)
Sets the data type for this form field.- Parameters:
type- the data type
-
getPropertyName
public String getPropertyName()
Returns the property name of this field if one is set.- Specified by:
getPropertyNamein interfaceFieldHandler- Returns:
- the property name
-
setPropertyName
public void setPropertyName(String n)
Sets the property name of this field.- Parameters:
n- the property name
-
getDisplayName
public String getDisplayName()
Returns the display name.- Specified by:
getDisplayNamein interfaceFieldHandler- Returns:
- the display name (can be null)
-
setDisplayName
public void setDisplayName(String displayName)
Sets the display name.- Parameters:
displayName- the new display name
-
validate
public ValidationResult validate(ValidationPhase phase)
Performs validation for the specified phase and returns the results.- Specified by:
validatein interfaceFieldHandler- Parameters:
phase- the validation phase- Returns:
- the validation result
-
getData
public Object getData()
Fetches the data of this field. This method requires that validation of both the field and form level succeeded (it is guaranteed that themethod was called for these phases before the form framework invokes this method).validate(ValidationPhase)- Specified by:
getDatain interfaceFieldHandler- Returns:
- the data of this field (converted to the resulting type)
-
setData
public void setData(Object data)
Sets the data for this field. Converts the passed in object to the component handler's data type using the write transformer.- Specified by:
setDatain interfaceFieldHandler- Parameters:
data- the data object for this field
-
validateFieldLevel
protected ValidationResult validateFieldLevel()
Performs validation on the field level.- Returns:
- validation results
-
validateFormLevel
protected ValidationResult validateFormLevel()
Performs validation on the form level. This implementation transforms the GUI component's data into its target data type (assuming that field level validation was successful). Then the correctness is checked. If this validation is successful, too, the data object is stored internally so it can be accessed by thegetData()method.- Returns:
- validation results
-
fetchFieldData
protected Object fetchFieldData()
Fetches the form field's data directly from the component handler. This method is called whenever access to the field data is needed, especially by thevalidate()method. It assumes that validation on the field level was successful.- Returns:
- the field's data
-
validateFieldData
protected ValidationResult validateFieldData(Object data)
Performs a form level validation of this field. Checks if the passed in data object is semantically correct.- Parameters:
data- the data to check- Returns:
- a validation result object with the results of the form level validation
-
-