net.sourceforge.stripes.validation
Class ValidationErrors

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,List<ValidationError>>
          extended by net.sourceforge.stripes.validation.ValidationErrors
All Implemented Interfaces:
Serializable, Cloneable, Map<String,List<ValidationError>>

public class ValidationErrors
extends HashMap<String,List<ValidationError>>

Container class for ValidationErrors that are tied to form fields. All of the regular Map methods are available and can be used. In addition there are a number of utility methods which are design to make it easier to interact with the data.

Author:
Tim Fennell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
static String GLOBAL_ERROR
          Key that is used to store global (i.e.
 
Constructor Summary
ValidationErrors()
           
 
Method Summary
 void add(String field, ValidationError error)
          Synonym for put(String field, ValidationError error).
 void addAll(String field, List<ValidationError> errors)
          Synonym for putAll().
 void addGlobalError(ValidationError error)
          Allows for the addition of errors that are not tied to a specific field.
 boolean hasFieldErrors()
          Returns true if there are field-specific errors present, and false if there are only global errors, or no errors at all.
 List<ValidationError> put(String field, List<ValidationError> errors)
          Replaces the list of errors for a given field with the list supplied.
 void put(String field, ValidationError error)
          Adds an error message for the field specified.
 void putAll(String field, List<ValidationError> errors)
          Add multiple errors for a particular field.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

GLOBAL_ERROR

public static final String GLOBAL_ERROR
Key that is used to store global (i.e. non-field specific) errors.

See Also:
Constant Field Values
Constructor Detail

ValidationErrors

public ValidationErrors()
Method Detail

put

public void put(String field,
                ValidationError error)
Adds an error message for the field specified. Will lazily instantiate a List<ValidationError> and insert it into the map if necessary.

Parameters:
field - the name of the field in error
error - a ValidationError to add to that field

add

public void add(String field,
                ValidationError error)
Synonym for put(String field, ValidationError error). Adds an error message for the field specified. Will lazily instantiate a List<ValidationError> and insert it into the map if necessary.

Parameters:
field - the name of the field in error
error - a ValidationError to add to that field

putAll

public void putAll(String field,
                   List<ValidationError> errors)
Add multiple errors for a particular field. Does not destroy or override any existing errors. Purely a convenience method to avoid having to check and possibly instantiate the collection of errors for a field if it does not already exist.

Parameters:
field - the name of the field in error
errors - a non-null list of errors to add for the field

addAll

public void addAll(String field,
                   List<ValidationError> errors)
Synonym for putAll(). Add multiple errors for a particular field. Does not destroy or override any existing errors. Purely a convenience method to avoid having to check and possibly instantiate the collection of errors for a field if it does not already exist.

Parameters:
field - the name of the field in error
errors - a non-null list of errors to add for the field

addGlobalError

public void addGlobalError(ValidationError error)
Allows for the addition of errors that are not tied to a specific field. Errors added in this way will only be displayed as part of the complete list of errors, and never when showing errors for a specific field.


put

public List<ValidationError> put(String field,
                                 List<ValidationError> errors)
Replaces the list of errors for a given field with the list supplied.

Specified by:
put in interface Map<String,List<ValidationError>>
Overrides:
put in class HashMap<String,List<ValidationError>>
Parameters:
field - the name of the field in error
errors - the list of validation errors for the field
Returns:
the previous errors for the field, or null if there were none

hasFieldErrors

public boolean hasFieldErrors()
Returns true if there are field-specific errors present, and false if there are only global errors, or no errors at all.

Returns:
true if field errors exist, false otherwise


? Copyright 2005-2006, Stripes Development Team.