org.barracudamvc.core.forms
Class ErrorManager

java.lang.Object
  extended byorg.barracudamvc.core.forms.ErrorManager

public class ErrorManager
extends Object

This class is used to collate all the nested exceptions on a form into something that can be easily accessed. To use it, you typically call ErrorManager.handleError(ValidationException). You can also manually add errors. You can them use the ErrorManager to flag any components to which it relates (in other words, by calling ErrorHandler.apply(bcomp), the error manager will automatically use the component name to look up any validation exceptions which correspond to a form element of the same name, and if a match occurs, will automatically adjust the component by setting its css class attribute to "invalid" and setting the title attribute with the error description. This makes it possible to visibly flag components which have errors - when the user mouses over they see the err). The way you use this class is to call try { form.map(); form.validate(); catch (ValdationException ve) { ErrorManager.handleError(ve); } Now the error manager is actually populated and ready to use. For convenience sake, a copy is stored in the local object repositry, and can be accessed later simply by calling ErrorManager eman = ErrorManager.getInstance(); Note that now the ErrorManager is integrated with DefaultFormMap - when you call FormMap.validate() it automatically set up the error manager if there are errors so that you don't need to manually call ErrorManager.handleError(). If you DO manually call this method, however, it shouldn't hurt anything.

Since:
csc_110304_1
Author:
christianc@atmreports.com

Field Summary
static String ERROR_MANAGER
           
protected  List errors
           
protected  Map fieldErrors
           
protected  Map handledExceptions
           
static String INVALID_CSS_CLASS
           
protected static org.apache.log4j.Logger logger
           
 
Constructor Summary
ErrorManager()
          Create an empty error manager
ErrorManager(Exception error)
          Create a new error manager for a specific exception.
 
Method Summary
protected  void _addError(String key, Object error)
           
 void addError(Object error)
          Add an error to the handler (this method recursively adds any errors which may be nested within this error as well, ie. in the case of ValidationExceptions.
 void addError(String key, Object error)
          Add an error to the handler (this method recursively adds any errors which may be nested within this error as well, ie. in the case of ValidationExceptions.
 void apply(BComponent component)
          This method applies any errors which are associated with this component.
 List getErrors()
          Get a List of errors associated with this error manager
 Object getFieldError(String key)
          Get any errors associated with particular fields
 Map getFieldErrors()
          Get a Map of all errors associated with particular fields
static ErrorManager getInstance()
          Convenience method to get the current ErrorManager (if there are any errors).
static ErrorManager handleError(Exception error)
          Convenience method to initialize an ErrorManager from an error.
static ErrorManager handleError(String key, Exception error)
           
 boolean hasErrors()
          Returns true if there are non-field-related errors
 boolean hasFieldError(String key)
          Returns true if there are field-related errors
 boolean hasFieldErrors()
          Returns true if there are field-related errors
static void reset()
          Resets the error manager to a clear state (no errs)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

INVALID_CSS_CLASS

public static final String INVALID_CSS_CLASS
See Also:
Constant Field Values

ERROR_MANAGER

public static final String ERROR_MANAGER

errors

protected List errors

fieldErrors

protected Map fieldErrors

handledExceptions

protected Map handledExceptions
Constructor Detail

ErrorManager

public ErrorManager()
Create an empty error manager


ErrorManager

public ErrorManager(Exception error)
Create a new error manager for a specific exception. Most of the time you will use the handleError factory method instead of instantiating the form directly. The error passed to the constructor will automatically be added to the handler.

Parameters:
error - the actual root error this form is being associated
Method Detail

addError

public void addError(Object error)
Add an error to the handler (this method recursively adds any errors which may be nested within this error as well, ie. in the case of ValidationExceptions.

Parameters:
error - the actual error being associated

addError

public void addError(String key,
                     Object error)
Add an error to the handler (this method recursively adds any errors which may be nested within this error as well, ie. in the case of ValidationExceptions.

Parameters:
key - the name of the object to which the error is associated (usually the key name of the form element or the component name) A null value indicates its a general error, not associated with any particular field.
error - the actual error being associated

_addError

protected void _addError(String key,
                         Object error)

hasErrors

public boolean hasErrors()
Returns true if there are non-field-related errors


getErrors

public List getErrors()
Get a List of errors associated with this error manager


hasFieldErrors

public boolean hasFieldErrors()
Returns true if there are field-related errors


hasFieldError

public boolean hasFieldError(String key)
Returns true if there are field-related errors


getFieldError

public Object getFieldError(String key)
Get any errors associated with particular fields

Parameters:
key - the key name of the field
Returns:
either the actual error (String) or a List of such errors associated witht he field

getFieldErrors

public Map getFieldErrors()
Get a Map of all errors associated with particular fields


apply

public void apply(BComponent component)
This method applies any errors which are associated with this component. The component will have its class attribute adjusted (so that the error is visibly obvious). The title attribute will also be adjusted, so that a description of the error shows on mouse over.


handleError

public static ErrorManager handleError(Exception error)
Convenience method to initialize an ErrorManager from an error. You can access this error manager again/later simply by calling ErrorManager.getInstance(). It will be available until the request completes or until you call ErrorManager.reset().

Parameters:
error - Error to pass to the ErrorManager

handleError

public static ErrorManager handleError(String key,
                                       Exception error)

getInstance

public static ErrorManager getInstance()
Convenience method to get the current ErrorManager (if there are any errors). Returns null if all is well.

Returns:
the current error manager (if exists)

reset

public static void reset()
Resets the error manager to a clear state (no errs)



Copyright © 2004 BarracudaMVC.org All Rights Reserved.