|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.owasp.esapi.ValidationErrorList
public class ValidationErrorList
The ValidationErrorList class defines a well-formed collection of ValidationExceptions so that groups of validation functions can be called in a non-blocking fashion.
To use the ValidationErrorList to execute groups of validation attempts, your controller code would look something like:
ValidationErrorList() errorList = new ValidationErrorList();. String name = getValidInput("Name", form.getName(), "SomeESAPIRegExName1", 255, false, errorList); String address = getValidInput("Address", form.getAddress(), "SomeESAPIRegExName2", 255, false, errorList); Integer weight = getValidInteger("Weight", form.getWeight(), 1, 1000000000, false, errorList); Integer sortOrder = getValidInteger("Sort Order", form.getSortOrder(), -100000, +100000, false, errorList); request.setAttribute( "ERROR_LIST", errorList );The at your view layer you would be able to retrieve all of your error messages via a helper function like:
public static ValidationErrorList getErrors() { HttpServletRequest request = ESAPI.httpUtilities().getCurrentRequest(); ValidationErrorList errors = new ValidationErrorList(); if (request.getAttribute(Constants.ERROR_LIST) != null) { errors = (ValidationErrorList)request.getAttribute("ERROR_LIST"); } return errors; }You can list all errors like:
<% for (Object vo : errorList.errors()) { ValidationException ve = (ValidationException)vo; %> <%= ESAPI.encoder().encodeForHTML(ve.getMessage()) %>And even check if a specific UI component is in error via calls like:
<% } %>
ValidationException e = errorList.getError("Name");
Constructor Summary | |
---|---|
ValidationErrorList()
|
Method Summary | |
---|---|
void |
addError(java.lang.String context,
ValidationException vex)
Adds a new error to list with a unique named context. |
java.util.List<ValidationException> |
errors()
Returns list of ValidationException, or empty list of no errors exist. |
ValidationException |
getError(java.lang.String context)
Retrieves ValidationException for given context if one exists. |
boolean |
isEmpty()
Returns true if no error are present. |
int |
size()
Returns the numbers of errors present. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ValidationErrorList()
Method Detail |
---|
public void addError(java.lang.String context, ValidationException vex)
context
- Unique named context for this ValidationErrorList
.vex
- A ValidationException
.public java.util.List<ValidationException> errors()
public ValidationException getError(java.lang.String context)
context
- unique name for each error
public boolean isEmpty()
public int size()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |