Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Validation

Validation is implemented in different areas of the application:

  1. Form Conversion (POJO)

    Attempts to convert incoming request parameters to the underlying type of the action form. If the parameter value cannot
    be converted to the type, an error is added, and control passed back to input jsp. ActionForm populate() method is the hook
    for this validation

  2. Validation against the data dictionary

    Validates form business objects against the restrictions defined in the data dictionary.

  3. Business Rules Container

    Executes business rules on document route (See the rules documentation for additional information on the application of business rules.)

Validation Framework Classes

  • org.kuali.rice.kns.util.ErrorMap
    Map that collects errors throughout a validation session. At each request, a new ErrorMap is added to
    GlobalVariables. Any method of the application can pull the ErrorMap out and add errors as needed:

    GlobalVariables.getMessageMap().put(propertyName,ErrorMap.ERROR_REQUIRED,propertyLabel)
    

    At the end of request processing, the ErrorMap is checked, and any errors are translated to ActionMessages for
    display in the jsp.

  • org.kuali.rice.kns.exceptions.ValidationException
    Any exceptions encountered by the validation framework are wrapped in a ValidationException.
  • org.kuali.rice.kns.service.(impl.)DictionaryValidationService(Impl) (junit org.kuali.rice.kns.service.DictionaryValidationServiceTest)
    Provides entry points to validation against the data dictionary.
  • errors.tag
    Provides display of errors in the UI. The keyMatch attribute is a comma delimited string of error keys to match on. The tag
    performs a like on each against error keys in the map.

    <kul:errors keyMatch="document.sourceAccountingLines, newSourceLine"/>
    

    The above would display any errors whose key starts with document.sourceAccountingLines or newSourceLine (e.g.,
    document.sourceAccountingLines.account.accountNbr, newSourceLine.projectCode, ...)

Adding Error Messages

  • When an error is encountered (e.g., in a Rule, or Business Object validation) add error to ErrorMap
  • GlobalVariables provides access to the ErrorMap for the request

    GlobalVariables.getMessageMap().put(RicePropertyConstants.DOCUMENT+"."+RicePropertyConstants.SOURCE_ACCOUNTING_LINE+"[" + accountingLineIndex + "]."+RiceProertyConstants.ACCOUNT+"."+RicePropertyConstants.ACCOUNT_NUMBER,ERROR_CONSTANTS.ERROR_NOT_VALID,accountNumber);
    
  • The first parameter to the ErrorMap is the fully qualified path to the field on the action form, less any prefix terms that have been added to the ErrorMap using the addToErrorPath method.

    GlobalVariables.getMessageMap().addToErrorPath(RicePropertyConstants.DOCUMENT+"."+RicePropertyConstants.SOURCE_ACCOUNTING_LINE+"[" + accountingLineIndex + "]");
    
    GlobalVariables.getMessageMap().put(RicePropertyConstants.ACCOUNT+"."+RicePropertyConstants.ACCOUNT_NUMBER,ERROR_CONSTANTS.ERROR_NOT_VALID,accountNumber);
     ....
    GlobalVariables.getMessageMap().removeFromErrorPath(RicePropertyConstants.DOCUMENT+RicePropertyConstants.SOURCE_ACCOUNTING_LINE+"[" + accountingLineIndex + "]");
    

    For information on other methods available to manipulate the ErrorMap and ErrorPath refer to the ErrorMap javadoc.

  • The second parameter to the ErrorMap is the error constant for the error message.
  • The third parameter is any parameters for the message. If multiple parameters are needed, construct a string array (String[]) with the parameters.

The text for errors are maintained as system messages and can be changed or added by changing system messages.

 

 

Kuali documentation is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. 

Kuali software is licensed for use pursuant to the Affero General Public License, version 3.

 Copyright © 2014 Kuali, Inc. All rights reserved. 

Portions of Kuali are copyrighted by other parties as described in the Acknowledgments screen. 

Kuali ® is a registered trademark of the Trustees of Indiana University.

  • No labels