|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.barracudamvc.core.forms.ErrorManager
public class ErrorManager
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.
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 |
---|
protected static org.apache.log4j.Logger logger
public static final String INVALID_CSS_CLASS
public static final String ERROR_MANAGER
protected List errors
protected Map fieldErrors
protected Map handledExceptions
Constructor Detail |
---|
public ErrorManager()
public ErrorManager(Exception error)
error
- the actual root error this form is being associatedMethod Detail |
---|
public void addError(Object error)
error
- the actual error being associatedpublic void addError(String key, Object error)
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 associatedprotected void _addError(String key, Object error)
public boolean hasErrors()
public List getErrors()
public boolean hasFieldErrors()
public boolean hasFieldError(String key)
public Object getFieldError(String key)
key
- the key name of the field
public Map getFieldErrors()
public void apply(BComponent component)
public static ErrorManager handleError(Exception error)
error
- Error to pass to the ErrorManagerpublic static ErrorManager handleError(String key, Exception error)
public static ErrorManager getInstance()
public static void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |