Class FieldHelper


  • public class FieldHelper
    extends 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.
      • getClientFieldQualifier

        public static 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 String getClientFieldQualifier​(SlingHttpServletRequest request,
                                                     FieldDescription desc,
                                                     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.
      • getConstraintMessage

        public static 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.
      • 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.