Package com.day.cq.wcm.foundation.forms
Class ValidationInfo
java.lang.Object
com.day.cq.wcm.foundation.forms.ValidationInfo
This class collects validation information (error messages) for a
form.
-
Constructor Summary
ConstructorsConstructorDescriptionValidationInfo(SlingHttpServletRequest request) Construct a new validation info. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddConstraintError(SlingHttpServletRequest request, FieldDescription desc) Add the error message for the constraint of the field.static voidaddConstraintError(SlingHttpServletRequest request, FieldDescription desc, int valueIndex) Add the error message for the constraint of the field.voidaddErrorMessage(String field, String msg) Add the error message for the field.static ValidationInfoReturn the validation information for a request.String[]getErrorMessages(String field) Return all error messages for this parameter.String[]getErrorMessages(String field, int valueIndex) Return all error messages for this parameter.Return the form id.static ValidationInfoReturn the validation information for a requestString[]Return all values for a field.
-
Constructor Details
-
ValidationInfo
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
Return all values for a field.- Parameters:
field- The name of the field.- Returns:
- The array of values or
null
-
addErrorMessage
Add the error message for the field.- Parameters:
field- The name of the field ornullmsg- The error message.
-
addConstraintError
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
Return the form id.- Returns:
- The form id or
null
-
getErrorMessages
Return all error messages for this parameter.- Parameters:
field- Parameter name ornullto get global errors.- Returns:
nullif there are no messages
-
getErrorMessages
Return all error messages for this parameter.- Parameters:
field- Parameter name ornullto get global errors.valueIndex- value index- Returns:
nullif there are no messages- Since:
- 5.3
-
getValidationInfo
Return the validation information for a request- Parameters:
req- The current request.- Returns:
- The validation info for this request or
null
-
createValidationInfo
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
-