Validation and Error Handling
Validation
Validation is implemented in different areas of the application:
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 validationValidation against the data dictionary
Validates form business objects against the restrictions defined in the data dictionary.
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.kfs.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.kfs.kns.exceptions.ValidationException
Any exceptions encountered by the validation framework are wrapped in a ValidationException. - org.kuali.kfs.kns.service.(impl.)DictionaryValidationService(Impl) (junit org.kuali.kfs.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(KFSPropertyConstants.DOCUMENT+"."+KFSPropertyConstants.SOURCE_ACCOUNTING_LINE+"[" + accountingLineIndex + "]."+KFSPropertyConstants.ACCOUNT+"."+KFSPropertyConstants.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(KFSPropertyConstants.DOCUMENT+"."+KFSPropertyConstants.SOURCE_ACCOUNTING_LINE+"[" + accountingLineIndex + "]"); GlobalVariables.getMessageMap().put(KFSPropertyConstants.ACCOUNT+"."+KFSPropertyConstants.ACCOUNT_NUMBER,ERROR_CONSTANTS.ERROR_NOT_VALID,accountNumber); .... GlobalVariables.getMessageMap().removeFromErrorPath(KFSPropertyConstants.DOCUMENT+KFSPropertyConstants.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.