nl.openedge.baritus
Class FormBeanContext

java.lang.Object
  extended bynl.openedge.baritus.FormBeanContext
All Implemented Interfaces:
java.util.Map

public final class FormBeanContext
extends java.lang.Object
implements java.util.Map

FormBeanContext wraps the form bean, errors the current locale and overrideFields. Furthermore, it acts as a decorator for a HashMap where you can optionally store attributes you do not want to include as properties in your form bean.

Author:
Eelco Hillenius, Maurice Marrink

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static java.lang.String ERROR_KEY_EXCEPTION
          error key for stacktrace if any
static java.lang.String ERROR_KEY_STACKTRACE
          error key for stacktrace if any
 
Constructor Summary
FormBeanContext()
           
 
Method Summary
 void clear()
          clear the attributes
 boolean containsKey(java.lang.Object key)
          is the provided key the key of an attribute
 boolean containsValue(java.lang.Object value)
          is the provided value stored as an attribute
 java.lang.String displayProperty(java.lang.String name)
          Get the display string of the property with the given name without using a pattern.
 java.lang.String displayProperty(java.lang.String name, java.lang.String pattern)
          Get the display string of the property with the given name, optionally using the given pattern.
 java.util.Set entrySet()
          get the entries of the attributes
 java.lang.String format(java.lang.Object value)
          Format the given value, independent of the current form, using the class of the value to lookup a formatter.
 java.lang.String format(java.lang.Object value, java.lang.String pattern)
          Format the given value, independent of the current form, using the class of the value to lookup a formatter using the provided pattern.
 java.lang.String format(java.lang.String formatterName, java.lang.Object value)
          Format the given value, independent of the current form, using the provided name of the formatter to lookup the formatter or - if no formatter was found - using the class of the value to lookup the formatter.
 java.lang.String format(java.lang.String formatterName, java.lang.Object value, java.lang.String pattern)
          Format the given value, independent of the current form using: 1. look in the ConverterRegistry if a formatter was stored with the formatterName and optionally locale as key; 2. if not found, look in the ConverterRegistry if a formatter was stored with the pattern and optionally the locale as key; 3. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter);
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the attributes map maps the specified key.
 java.lang.Object getBean()
          Get the form bean.
 FormBeanCtrlBase getController()
          get current controller
 java.util.Locale getCurrentLocale()
          Get the current locale.
 java.lang.String getError(java.lang.String field)
          Get the registered error for one field.
 java.util.Map getErrors()
          Get the map with errors.
 Formatter getFormatter(java.lang.String formatterName, java.lang.String pattern, java.lang.Class clazz, java.util.Locale locale)
          Get the formatter for the given fieldname/ class/ locale. 1. look in the ConverterRegistry if a formatter was stored with the formatterName and optionally locale as key. 2. if not found, look in the ConverterRegistry if a formatter was stored with the pattern and optionally the locale as key. 3. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter).
 java.lang.Object getOverrideField(java.lang.String name)
          Get the value of the field that was overridden.
 java.util.Map getOverrideFields()
          Get the map of failed field values.
 boolean hasErrors()
          Whether any errors were registered during population/ validation.
 boolean isEmpty()
          are there any attributes
 java.util.Set keySet()
          get the key set of the attributes
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in the attribute map.
 void putAll(java.util.Map t)
          put the provided map in the attribute map
 java.lang.Object remove(java.lang.Object key)
          remove an attribute
 void removeError(java.lang.String key)
          De-register (remove) an error that was registered with the provided key.
 void setBean(java.lang.Object bean)
          Set the form bean.
 void setController(FormBeanCtrlBase controller)
          set current controller
 void setCurrentLocale(java.util.Locale locale)
          Set the current locale.
 void setError(java.lang.String key, java.lang.String value)
          Register (or overwrite) an error with the provided key and value.
 void setError(java.lang.String exceptionKey, java.lang.String stackTraceKey, java.lang.Throwable t)
          Add exception and its stacktrace.
 void setError(java.lang.String key, java.lang.Throwable t, boolean asStackTrace)
          Either add this exception with the given key, or add the stacktrace of this exception with the given key.
 void setError(java.lang.Throwable t)
          Adds an exception with key 'exception' and adds the stacktrace of this exception with key 'stacktrace'.
 void setError(java.lang.Throwable t, boolean asStackTrace)
          Adds an exception with key 'exception' and adds either the stacktrace of this exception with key 'stacktrace' if asStackTrace is true, or add the exception message with key 'exception' if asStackTrace is false.
 void setErrors(java.util.Map errors)
          Set the map of errors.
 void setOverrideField(java.util.Map fields)
          Set values of fields that have overrides.
 void setOverrideField(java.lang.String name, java.lang.Object value)
          Set value of field that overrides.
 int size()
          get the number of attributes
 java.lang.String toString()
          String rep.
 java.util.Collection values()
          get the attribute values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

ERROR_KEY_STACKTRACE

public static final java.lang.String ERROR_KEY_STACKTRACE
error key for stacktrace if any

See Also:
Constant Field Values

ERROR_KEY_EXCEPTION

public static final java.lang.String ERROR_KEY_EXCEPTION
error key for stacktrace if any

See Also:
Constant Field Values
Constructor Detail

FormBeanContext

public FormBeanContext()
Method Detail

getCurrentLocale

public java.util.Locale getCurrentLocale()
Get the current locale.

Returns:
Locale current locale

setCurrentLocale

public void setCurrentLocale(java.util.Locale locale)
Set the current locale.

Parameters:
locale - current locale

getBean

public java.lang.Object getBean()
Get the form bean. The current control provided a bean to populate with method makeFormBean. That bean is saved (before population) in the formBeanContext.

Returns:
Object the bean that will be populated, and that is returned by makeFormbean

setBean

public void setBean(java.lang.Object bean)
Set the form bean. This is the bean that will be populated, and that is returned by make formbean.

Parameters:
bean - the bean that will be populated, and that is returned by makeFormbean

getErrors

public java.util.Map getErrors()
Get the map with errors. Returns null if no errors are registered.

Returns:
Map map with errors or null if no errors are registered.

getError

public java.lang.String getError(java.lang.String field)
Get the registered error for one field. Returns null if no error is registered for the given field name.

Parameters:
field - name of the field to lookup the error for.
Returns:
String the error that was registered for the provided field name, or null if no error was registered for the provided field name.

setErrors

public void setErrors(java.util.Map errors)
Set the map of errors.

Parameters:
errors - The map of errors to set

setError

public void setError(java.lang.String key,
                     java.lang.Throwable t,
                     boolean asStackTrace)
Either add this exception with the given key, or add the stacktrace of this exception with the given key. Any value that was registered with the same key prior to this is overwritten.

Parameters:
key - key to store error under
t - exception
asStackTrace - if true, the stacktrace is added; otherwise the exception is added

setError

public void setError(java.lang.String exceptionKey,
                     java.lang.String stackTraceKey,
                     java.lang.Throwable t)
Add exception and its stacktrace. Any value that was registered with the same key prior to this is overwritten.

Parameters:
exceptionKey - key to use for exception
stackTraceKey - key to use for stacktrace
t - exception

setError

public void setError(java.lang.Throwable t)
Adds an exception with key 'exception' and adds the stacktrace of this exception with key 'stacktrace'. Any value that was registered with the same keys prior to this are overwritten.

Parameters:
t - exception

setError

public void setError(java.lang.Throwable t,
                     boolean asStackTrace)
Adds an exception with key 'exception' and adds either the stacktrace of this exception with key 'stacktrace' if asStackTrace is true, or add the exception message with key 'exception' if asStackTrace is false. Any value that was registered with the same keys prior to this are overwritten.

Parameters:
t - exception
asStackTrace - if true, the stacktrace is added; otherwise the exception

setError

public void setError(java.lang.String key,
                     java.lang.String value)
Register (or overwrite) an error with the provided key and value.

Parameters:
key - the key that the error should be registered with.
value - the value (message) of the error.

removeError

public void removeError(java.lang.String key)
De-register (remove) an error that was registered with the provided key.

Parameters:
key - the key that the error was registered with.

getOverrideFields

public java.util.Map getOverrideFields()
Get the map of failed field values.

Returns:
Map map with override fields

setOverrideField

public void setOverrideField(java.lang.String name,
                             java.lang.Object value)
Set value of field that overrides. WILL overwrite any allready registered override

Parameters:
name - name of the field/ property
value - usually the original input value

getOverrideField

public java.lang.Object getOverrideField(java.lang.String name)
Get the value of the field that was overridden. E.g. we got in a formbean property 'myDate' of type date. If form submit gives 'blah', this cannot be parsed as a date. Now, if setFailedField('myDate', 'blah') is called, the view can show the 'wrong' value transparently, as an Velocity EventCardridge will override any property with a failed field if set.

Parameters:
name - name of the field/ property
Returns:
Object usually the original input value

setOverrideField

public void setOverrideField(java.util.Map fields)
Set values of fields that have overrides. This WILL NOT overwrite allready registered overrides.

Parameters:
fields - map of fields to override the current values.

hasErrors

public boolean hasErrors()
Whether any errors were registered during population/ validation.

Returns:
boolean are there any errors registered for this formBean? True if so, false otherwise.

displayProperty

public java.lang.String displayProperty(java.lang.String name)
Get the display string of the property with the given name without using a pattern. If an object was found for the given property name, it will be formatted with the formatter found as follows: 1. look in the ConverterRegistry if a formatter was stored with the fieldname and optionally locale as key. 2. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter). If a formatter was found, it will be used for formatting the property (using the format(property, pattern) method). If not, ConvertUtils of the BeanUtils package is used to get the string representation of the property.

Parameters:
name - name of the property
Returns:
String the formatted value of the property of the current bean instance or the registered override value if any was registered.

displayProperty

public java.lang.String displayProperty(java.lang.String name,
                                        java.lang.String pattern)
Get the display string of the property with the given name, optionally using the given pattern. If an object was found for the given property name, it will be formatted with the formatter found as follows: 1. look in the ConverterRegistry if a formatter was stored with the fieldname and optionally locale as key. 2. if not found, look in the ConverterRegistry if a formatter was stored with the pattern and optionally the locale as key. 3. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter). If a formatter was found, it will be used for formatting the property (using the format(property, pattern) method). If not, ConvertUtils of the BeanUtils package is used to get the string representation of the property.

Parameters:
name - name of the property
pattern - optional pattern to use for formatting
Returns:
String the formatted value (using the pattern) of the property of the current bean instance or the registered override value if any was registered.

getFormatter

public Formatter getFormatter(java.lang.String formatterName,
                              java.lang.String pattern,
                              java.lang.Class clazz,
                              java.util.Locale locale)
Get the formatter for the given fieldname/ class/ locale. 1. look in the ConverterRegistry if a formatter was stored with the formatterName and optionally locale as key. 2. if not found, look in the ConverterRegistry if a formatter was stored with the pattern and optionally the locale as key. 3. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter).

Parameters:
formatterName - name of formatter
pattern - pattern: might be used as a key to store a Formatter
clazz - class of property
locale - locale to get Formatter for
Returns:
Formatter instance of Formatter if found, null otherwise

format

public java.lang.String format(java.lang.Object value)
Format the given value, independent of the current form, using the class of the value to lookup a formatter.

Parameters:
value - value to format
Returns:
String formatted value

format

public java.lang.String format(java.lang.Object value,
                               java.lang.String pattern)
Format the given value, independent of the current form, using the class of the value to lookup a formatter using the provided pattern.

Parameters:
value - value to format
pattern - pattern for format
Returns:
String formatted value

format

public java.lang.String format(java.lang.String formatterName,
                               java.lang.Object value)
Format the given value, independent of the current form, using the provided name of the formatter to lookup the formatter or - if no formatter was found - using the class of the value to lookup the formatter.

Parameters:
formatterName - name of formatter.
value - value to format
Returns:
String formatted value

format

public java.lang.String format(java.lang.String formatterName,
                               java.lang.Object value,
                               java.lang.String pattern)
Format the given value, independent of the current form using: 1. look in the ConverterRegistry if a formatter was stored with the formatterName and optionally locale as key; 2. if not found, look in the ConverterRegistry if a formatter was stored with the pattern and optionally the locale as key; 3. if not found, look in the ConverterRegistry if a Converter was stored for the type of the property that implements Formatter (as well as Converter);

Parameters:
formatterName - name of formatter.
value - value to format
pattern - pattern for format
Returns:
String formatted value

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the attributes map maps the specified key. Returns null if the map contains no mapping for this key.

Specified by:
get in interface java.util.Map
Parameters:
key - key whose associated value is to be returned
Returns:
Object the value to which the attributes map maps the specified key, or null if the map contains no mapping for this key.
See Also:
Map.get(java.lang.Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in the attribute map. If the attribute map previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface java.util.Map
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
See Also:
Map.put(java.lang.Object, java.lang.Object)

values

public java.util.Collection values()
get the attribute values

Specified by:
values in interface java.util.Map
Returns:
Collection the attribute values or null if no attributes were set
See Also:
Map.values()

keySet

public java.util.Set keySet()
get the key set of the attributes

Specified by:
keySet in interface java.util.Map
Returns:
Set the key set of the attributes or null if no attributes were set
See Also:
Map.keySet()

clear

public void clear()
clear the attributes

Specified by:
clear in interface java.util.Map
See Also:
Map.clear()

size

public int size()
get the number of attributes

Specified by:
size in interface java.util.Map
Returns:
int the number of attributes
See Also:
Map.size()

putAll

public void putAll(java.util.Map t)
put the provided map in the attribute map

Specified by:
putAll in interface java.util.Map
Parameters:
t - map to put in attributes
See Also:
Map.putAll(java.util.Map)

entrySet

public java.util.Set entrySet()
get the entries of the attributes

Specified by:
entrySet in interface java.util.Map
Returns:
Set the entries of the attributes or null if no attributes were set
See Also:
Map.entrySet()

containsKey

public boolean containsKey(java.lang.Object key)
is the provided key the key of an attribute

Specified by:
containsKey in interface java.util.Map
Parameters:
key - the key to look for
Returns:
boolean is the provided key the key of an attribute
See Also:
Map.containsKey(java.lang.Object)

isEmpty

public boolean isEmpty()
are there any attributes

Specified by:
isEmpty in interface java.util.Map
Returns:
boolean are there any attributes
See Also:
Map.isEmpty()

remove

public java.lang.Object remove(java.lang.Object key)
remove an attribute

Specified by:
remove in interface java.util.Map
Parameters:
key - key of the attribute to remove
Returns:
Object the object that was stored under the given key, if any
See Also:
Map.remove(java.lang.Object)

containsValue

public boolean containsValue(java.lang.Object value)
is the provided value stored as an attribute

Specified by:
containsValue in interface java.util.Map
Parameters:
value - the value to look for
Returns:
boolean is the provided value stored as an attribute
See Also:
Map.containsValue(java.lang.Object value)

getController

public FormBeanCtrlBase getController()
get current controller

Returns:
FormBeanCtrlBase

setController

public void setController(FormBeanCtrlBase controller)
set current controller

Parameters:
controller - current controller

toString

public java.lang.String toString()
String rep.

See Also:
Object.toString()


Copyright © 2003-2004 Open Edge. All Rights Reserved.