Class FieldHelper

java.lang.Object
com.day.cq.wcm.foundation.forms.FieldHelper

public class FieldHelper extends Object
Helper class for the field components.
Since:
5.3
  • Method Details

    • 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, 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
      IOException - if given resource can not be included
    • 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.
    • writeClientRequiredCheck

      public static void writeClientRequiredCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws IOException
      Write the client java script code to check a required field on form submit.
      Parameters:
      request - request
      response - response
      desc - field description
      Throws:
      IOException - if write caused an error
    • 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.
    • writeClientRegexpText

      public static void writeClientRegexpText(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc, String regexp) throws IOException
      Write client regexp text.
      Parameters:
      request - request
      response - response
      desc - field description
      regexp - regexp text
      Throws:
      IOException - if write caused an error
    • writeClientConstraintCheck

      public static void writeClientConstraintCheck(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws IOException, ServletException
      Write the client java script code to check a constraint on form submit.
      Parameters:
      request - request
      response - response
      desc - field description
      Throws:
      IOException - if write caused an error
      ServletException - if write caused an error
    • checkConstraint

      public static void checkConstraint(SlingHttpServletRequest request, SlingHttpServletResponse response, FieldDescription desc) throws 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:
      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.