public class ValidationErrorList extends Object
To use the ValidationErrorList to execute groups of validation attempts, your controller code would look something like:
ValidationErrorList() errorList = new ValidationErrorList(); String name = ESAPI.validator().getValidInput("Name", form.getName(), "SomeESAPIRegExName1", 255, false, errorList); String address = ESAPI.validator().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 and Description |
---|
ValidationErrorList() |
Modifier and Type | Method and Description |
---|---|
void |
addError(String context,
ValidationException vex)
Adds a new error to list with a unique named context.
|
List<ValidationException> |
errors()
Returns list of ValidationException, or empty list of no errors exist.
|
ValidationException |
getError(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.
|
public void addError(String context, ValidationException vex)
context
- Unique named context for this ValidationErrorList
.vex
- A ValidationException
.public List<ValidationException> errors()
public ValidationException getError(String context)
context
- unique name for each errorpublic boolean isEmpty()
public int size()
Copyright © 2023 The Open Worldwide Application Security Project (OWASP). All rights reserved.