Package com.day.cq.wcm.foundation.forms
Class FieldHelper
- java.lang.Object
-
- com.day.cq.wcm.foundation.forms.FieldHelper
-
public class FieldHelper extends java.lang.Object
Helper class for the field components.- Since:
- 5.3
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addDescription(SlingHttpServletRequest req, FieldDescription desc)
Add a field description for the field.static void
checkConstraint(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc)
Convenience method to check the constraint of a field element.static boolean
checkRequired(SlingHttpServletRequest request, FieldDescription desc)
Convenience method to check the required flag of a field element.static FieldDescription
createDefaultDescription(SlingHttpServletRequest req, Resource rsrc)
Create a default field description for the field.static java.lang.String
getClientFieldQualifier(SlingHttpServletRequest request, FieldDescription desc)
Get the full qualified path to the field to be used in client java script.static java.lang.String
getClientFieldQualifier(SlingHttpServletRequest request, FieldDescription desc, java.lang.String suffix)
Get the full qualified path to a suffixed field (e.g.static FieldDescription
getConstraintFieldDescription(SlingHttpServletRequest req)
Return the current field description.static java.lang.String
getConstraintMessage(FieldDescription desc, SlingHttpServletRequest request)
Return the error message for the constraint of the field.static FieldDescription[]
getFieldDescriptions(SlingHttpServletRequest req, Resource rsrc)
Return all field descriptions associated with this field.static void
initializeField(SlingHttpServletRequest req, SlingHttpServletResponse res, Resource rsrc)
Call the initialize script for the field.static void
writeClientConstraintCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc)
Write the client java script code to check a constraint on form submit.static void
writeClientRegexpText(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc, java.lang.String regexp)
Write client regexp text.static void
writeClientRequiredCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc)
Write the client java script code to check a required field on form submit.
-
-
-
Method Detail
-
createDefaultDescription
public static FieldDescription createDefaultDescription(SlingHttpServletRequest req, Resource rsrc)
Create a default field description for the field. This methods creates a new field description viaFieldDescription(Resource)
and associates this with the resource. If this method is invoked twice for the same resource and request combination, the default description is added twice as well!- Parameters:
req
- The current request.rsrc
- The field resource.- Returns:
- The new field description.
-
addDescription
public static void addDescription(SlingHttpServletRequest req, FieldDescription desc)
Add a field description for the field.- Parameters:
req
- The current request.desc
- The new field description.
-
getFieldDescriptions
public static FieldDescription[] getFieldDescriptions(SlingHttpServletRequest req, Resource rsrc)
Return all field descriptions associated with this field.- Parameters:
req
- The current request.rsrc
- The field resource.- Returns:
- The descriptions for this field.
-
initializeField
public static void initializeField(SlingHttpServletRequest req, SlingHttpServletResponse res, Resource rsrc) throws ServletException, java.io.IOException
Call the initialize script for the field.- Parameters:
req
- The current request.res
- The current response.rsrc
- The field resource.- Throws:
ServletException
- if given resource can not be includedjava.io.IOException
- if given resource can not be included
-
getClientFieldQualifier
public static java.lang.String getClientFieldQualifier(SlingHttpServletRequest request, FieldDescription desc)
Get the full qualified path to the field to be used in client java script.- Parameters:
request
- requestdesc
- description- Returns:
- path to the field
-
getClientFieldQualifier
public static java.lang.String getClientFieldQualifier(SlingHttpServletRequest request, FieldDescription desc, java.lang.String suffix)
Get the full qualified path to a suffixed field (e.g. @Write) to be used in client java script.- Parameters:
request
- The requestdesc
- The field descriptionsuffix
- The suffix- Returns:
- The qualified path
- Since:
- 5.5
-
getConstraintFieldDescription
public static FieldDescription getConstraintFieldDescription(SlingHttpServletRequest req)
Return the current field description. This method can be used by constraints to get the current field description.- Parameters:
req
- request- Returns:
- The current field description.
-
writeClientRequiredCheck
public static void writeClientRequiredCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws java.io.IOException
Write the client java script code to check a required field on form submit.- Parameters:
request
- requestresponse
- responsedesc
- field description- Throws:
java.io.IOException
- if write caused an error
-
getConstraintMessage
public static java.lang.String getConstraintMessage(FieldDescription desc, SlingHttpServletRequest request)
Return 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:
desc
- The field description.request
- The current request.- Returns:
- The constraint error message.
-
writeClientRegexpText
public static void writeClientRegexpText(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc, java.lang.String regexp) throws java.io.IOException
Write client regexp text.- Parameters:
request
- requestresponse
- responsedesc
- field descriptionregexp
- regexp text- Throws:
java.io.IOException
- if write caused an error
-
writeClientConstraintCheck
public static void writeClientConstraintCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws java.io.IOException, ServletException
Write the client java script code to check a constraint on form submit.- Parameters:
request
- requestresponse
- responsedesc
- field description- Throws:
java.io.IOException
- if write caused an errorServletException
- if write caused an error
-
checkConstraint
public static void checkConstraint(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws java.io.IOException, ServletException
Convenience method to check the constraint of a field element. If the field has a constraint and is not empty, the constraint is checked.- Parameters:
request
- The current request.response
- The current response.desc
- The field description.- Throws:
java.io.IOException
- if check caused an errorServletException
- if check caused an error
-
checkRequired
public static boolean checkRequired(SlingHttpServletRequest request, FieldDescription desc)
Convenience method to check the required flag of a field element.- Parameters:
request
- The current element.desc
- The field description.- Returns:
- true if check passed.
-
-