Class FieldHelper


  • public class FieldHelper
    extends java.lang.Object
    Helper class for the field components.
    Since:
    5.3
    • 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 via FieldDescription(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 included
        java.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 - request
        desc - 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 request
        desc - The field description
        suffix - 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 - request
        response - response
        desc - 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 - request
        response - response
        desc - field description
        regexp - regexp text
        Throws:
        java.io.IOException - 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 error
        ServletException - 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.