Package com.day.cq.wcm.foundation.forms
Class ValidationInfo
- java.lang.Object
-
- com.day.cq.wcm.foundation.forms.ValidationInfo
-
public class ValidationInfo extends java.lang.Object
This class collects validation information (error messages) for a form.
-
-
Constructor Summary
Constructors Constructor Description ValidationInfo(SlingHttpServletRequest request)
Construct a new validation info.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addConstraintError(SlingHttpServletRequest request, FieldDescription desc)
Add the error message for the constraint of the field.static void
addConstraintError(SlingHttpServletRequest request, FieldDescription desc, int valueIndex)
Add the error message for the constraint of the field.void
addErrorMessage(java.lang.String field, java.lang.String msg)
Add the error message for the field.static ValidationInfo
createValidationInfo(SlingHttpServletRequest req)
Return the validation information for a request.java.lang.String[]
getErrorMessages(java.lang.String field)
Return all error messages for this parameter.java.lang.String[]
getErrorMessages(java.lang.String field, int valueIndex)
Return all error messages for this parameter.java.lang.String
getFormId()
Return the form id.static ValidationInfo
getValidationInfo(HttpServletRequest req)
Return the validation information for a requestjava.lang.String[]
getValues(java.lang.String field)
Return all values for a field.
-
-
-
Constructor Detail
-
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 Detail
-
getValues
public java.lang.String[] getValues(java.lang.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(java.lang.String field, java.lang.String msg)
Add the error message for the field.- Parameters:
field
- The name of the field ornull
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 java.lang.String getFormId()
Return the form id.- Returns:
- The form id or
null
-
getErrorMessages
public java.lang.String[] getErrorMessages(java.lang.String field)
Return all error messages for this parameter.- Parameters:
field
- Parameter name ornull
to get global errors.- Returns:
null
if there are no messages
-
getErrorMessages
public java.lang.String[] getErrorMessages(java.lang.String field, int valueIndex)
Return all error messages for this parameter.- Parameters:
field
- Parameter name ornull
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
-
-