Class ValidationErrorList


  • public class ValidationErrorList
    extends java.lang.Object
    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");
     
    Since:
    August 15, 2008
    Author:
    Jim Manico (jim@manico.net) Manico.net
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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

      • ValidationErrorList

        public ValidationErrorList()
    • Method Detail

      • addError

        public void addError​(java.lang.String context,
                             ValidationException vex)
        Adds a new error to list with a unique named context. No action taken if either element is null. Existing contexts will be overwritten.
        Parameters:
        context - Unique named context for this ValidationErrorList.
        vex - A ValidationException.
      • errors

        public java.util.List<ValidationException> errors()
        Returns list of ValidationException, or empty list of no errors exist.
        Returns:
        List
      • getError

        public ValidationException getError​(java.lang.String context)
        Retrieves ValidationException for given context if one exists.
        Parameters:
        context - unique name for each error
        Returns:
        ValidationException or null for given context
      • isEmpty

        public boolean isEmpty()
        Returns true if no error are present.
        Returns:
        boolean
      • size

        public int size()
        Returns the numbers of errors present.
        Returns:
        boolean