Class ClientValidationUtils

java.lang.Object
org.kuali.rice.krad.uif.util.ClientValidationUtils

public class ClientValidationUtils extends Object
Contains all the methods necessary for generating the js required to perform validation client side. The processAndApplyConstraints(InputField field, View view) is the key method of this class used by InputField to setup its client side validation mechanisms. Methods now take into account state based validation and states on constraints.
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Details

  • Constructor Details

    • ClientValidationUtils

      public ClientValidationUtils()
  • Method Details

    • generateMessageText

      public static String generateMessageText(String namespace, String componentCode, String messageKey, List<String> params)
      Returns formatted message text for the given message namespace, component, and key
      Parameters:
      namespace - namespace code the message is associated with, if null the default namespace will be used
      componentCode - component code the message is associated with, if null default component code is used
      messageKey - key for the message to retrieve
      params - list of parameters for the message text
      Returns:
      formatted message text
    • generateValidatorMessagesOption

      public static String generateValidatorMessagesOption()
      Generates the js object used to override all default messages for validator jquery plugin with custom messages retrieved from the message service
      Returns:
      script for message override
    • getRegexMethod

      public static String getRegexMethod(InputField field, ValidCharactersConstraint validCharactersConstraint)
      Returns the add method jquery validator call for the regular expression stored in validCharactersConstraint.
      Parameters:
      field - input field
      validCharactersConstraint - constraint providing the regex
      Returns:
      js validator.addMethod script
    • getRegexMethod

      public static String getRegexMethod(InputField field, ValidCharactersConstraint validCharactersConstraint, boolean escape)
      Returns the add method jquery validator call for the regular expression stored in validCharactersConstraint.
      Parameters:
      field - input field
      validCharactersConstraint - constraint providing the regex
      escape - whether to escape key or not
      Returns:
      js validator.addMethod script
    • getRegexMethodWithBooleanCheck

      public static String getRegexMethodWithBooleanCheck(InputField field, ValidCharactersConstraint validCharactersConstraint)
      Returns the add method jquery validator call for the regular expression stored in validCharactersConstraint that explicitly checks a boolean. Needed because one method accepts params and the other doesn't.
      Parameters:
      field - input field
      validCharactersConstraint - constraint providing the regex
      Returns:
      js validator.addMethod script
    • processCaseConstraint

      public static void processCaseConstraint(InputField field, View view, CaseConstraint constraint, String andedCase, String validationState, StateMapping stateMapping)
      This method processes a single CaseConstraint. Internally it makes calls to processWhenConstraint for each WhenConstraint that exists in this constraint. It adds a "dependsOn" css class to this field for the field which the CaseConstraint references.
      Parameters:
      field - input field
      view - active view
      constraint - case constraint providing the field reference
      andedCase - the boolean logic to be anded when determining if this case is satisfied (used for nested CaseConstraints)
      validationState - validation state
      stateMapping - state mapping
    • addScriptToPage

      public static void addScriptToPage(View view, InputField field, String script)
      Adds the script to the view to execute on a jQuery document ready event.
      Parameters:
      view - active view
      field - input field
      script - script to run on the document ready event
    • processPrerequisiteConstraint

      public static void processPrerequisiteConstraint(InputField field, PrerequisiteConstraint constraint, View view)
      Simpler version of processPrerequisiteConstraint
      Parameters:
      field - input field
      constraint - prerequisite constraint to process
      view - active view
      See Also:
    • processPrerequisiteConstraint

      public static void processPrerequisiteConstraint(InputField field, PrerequisiteConstraint constraint, View view, String booleanStatement)
      Processes a Prerequisite constraint that should be applied when the booleanStatement passed in evaluates to true.
      Parameters:
      field - input field
      constraint - prerequisite constraint to process
      view - active view
      booleanStatement - the booleanstatement in js - should return true when the validation rule should be applied
    • processMustOccurConstraint

      public static void processMustOccurConstraint(InputField field, View view, MustOccurConstraint mc, String booleanStatement)
      This method processes the MustOccurConstraint. The constraint is only applied when the booleanStatement evaluates to true during validation. This method creates the addMethod and add rule calls for the jquery validation plugin necessary for applying this constraint to this field.
      Parameters:
      field - input field
      view - active view
      mc - must occur constraint to process
      booleanStatement - the booleanstatement in js - should return true when the validation rule should be applied
    • processAndApplyConstraints

      public static void processAndApplyConstraints(InputField field, View view, Object model)
      This method processes all the constraints on the InputField passed in and adds all the necessary jQuery and js required (validator's rules, methods, and messages) to the View's onDocumentReady call. The result is js that will validate all the constraints contained on an InputField during user interaction with the field using the jQuery validation plugin and custom code.
      Parameters:
      field - input field
      view - active view
      model - active model