Class ValidationInfo

java.lang.Object
com.day.cq.wcm.foundation.forms.ValidationInfo

public class ValidationInfo extends Object
This class collects validation information (error messages) for a form.
  • Constructor Details

    • ValidationInfo

      public ValidationInfo(SlingHttpServletRequest request)
      Construct a new validation info. The validation info stores the form id, all content request parameters and their values together with possible validation messages.
      Parameters:
      request - The current request.
  • Method Details

    • getValues

      public String[] getValues(String field)
      Return all values for a field.
      Parameters:
      field - The name of the field.
      Returns:
      The array of values or null
    • addErrorMessage

      public void addErrorMessage(String field, String msg)
      Add the error message for the field.
      Parameters:
      field - The name of the field or null
      msg - The error message.
    • addConstraintError

      public static void addConstraintError(SlingHttpServletRequest request, FieldDescription desc)
      Add the error message for the constraint of the field. If the field description has a constraint message, this message is used, if not a default constraint message is looked up from the constraint resource. If no such message is available, "Field is not valid" is used as the message.
      Parameters:
      request - The current request usually targetting a constraint resource.
      desc - The field description.
      Since:
      5.3
    • addConstraintError

      public static void addConstraintError(SlingHttpServletRequest request, FieldDescription desc, int valueIndex)
      Add the error message for the constraint of the field. If the field description has a constraint message, this message is used, if not a default constraint message is looked up from the constraint resource. If no such message is available, "Field is not valid" is used as the message.
      Parameters:
      request - The current request usually targetting a constraint resource.
      desc - The field description.
      valueIndex - The value index.
      Since:
      5.3
    • getFormId

      public String getFormId()
      Return the form id.
      Returns:
      The form id or null
    • getErrorMessages

      public String[] getErrorMessages(String field)
      Return all error messages for this parameter.
      Parameters:
      field - Parameter name or null to get global errors.
      Returns:
      null if there are no messages
    • getErrorMessages

      public String[] getErrorMessages(String field, int valueIndex)
      Return all error messages for this parameter.
      Parameters:
      field - Parameter name or null to get global errors.
      valueIndex - value index
      Returns:
      null if there are no messages
      Since:
      5.3
    • getValidationInfo

      public static ValidationInfo getValidationInfo(HttpServletRequest req)
      Return the validation information for a request
      Parameters:
      req - The current request.
      Returns:
      The validation info for this request or null
    • createValidationInfo

      public static ValidationInfo createValidationInfo(SlingHttpServletRequest req)
      Return the validation information for a request. If a validation info is already associated with the request, this info is returned, otherwise a new one is created, associated with the request and returned.
      Parameters:
      req - The current request.
      Returns:
      The validation info