From: Juergen H. <jho...@us...> - 2006-04-21 00:13:55
|
Update of /cvsroot/springframework/spring/src/org/springframework/validation In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19629/src/org/springframework/validation Modified Files: Tag: mbranch-1-2 ValidationUtils.java Log Message: backported fixes and enhancements from 2.0 M4 (HEAD) Index: ValidationUtils.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/validation/ValidationUtils.java,v retrieving revision 1.14 retrieving revision 1.14.4.1 diff -C2 -d -r1.14 -r1.14.4.1 *** ValidationUtils.java 13 Sep 2005 21:23:20 -0000 1.14 --- ValidationUtils.java 21 Apr 2006 00:13:50 -0000 1.14.4.1 *************** *** 1,11 **** /* ! * Copyright 2002-2005 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, --- 1,11 ---- /* ! * Copyright 2002-2006 the original author or authors. ! * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at ! * * http://www.apache.org/licenses/LICENSE-2.0 ! * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, *************** *** 27,32 **** * implementations can become one-liners. * - * <p>Used by BindUtils' <code>bindAndValidate</code> method. - * * @author Juergen Hoeller * @author Dmitriy Kopylenko --- 27,30 ---- *************** *** 34,38 **** * @see Validator * @see Errors - * @see org.springframework.web.bind.BindUtils#bindAndValidate */ public abstract class ValidationUtils { --- 32,35 ---- *************** *** 40,59 **** private static Log logger = LogFactory.getLog(ValidationUtils.class); /** * Invoke the given validator for the given object and Errors instance. * @param validator validator to be invoked, or <code>null</code> if no validation ! * @param object object to bind the parameters to * @param errors Errors instance that should store the errors */ ! public static void invokeValidator(Validator validator, Object object, Errors errors) { if (validator != null) { if (logger.isDebugEnabled()) { logger.debug("Invoking validator [" + validator + "]"); } ! if (!validator.supports(object.getClass())) { throw new IllegalArgumentException("Validator " + validator.getClass() + ! " does not support " + object.getClass()); } ! validator.validate(object, errors); if (logger.isDebugEnabled()) { if (errors.hasErrors()) { --- 37,57 ---- private static Log logger = LogFactory.getLog(ValidationUtils.class); + /** * Invoke the given validator for the given object and Errors instance. * @param validator validator to be invoked, or <code>null</code> if no validation ! * @param obj object to bind the parameters to * @param errors Errors instance that should store the errors */ ! public static void invokeValidator(Validator validator, Object obj, Errors errors) { if (validator != null) { if (logger.isDebugEnabled()) { logger.debug("Invoking validator [" + validator + "]"); } ! if (obj != null && !validator.supports(obj.getClass())) { throw new IllegalArgumentException("Validator " + validator.getClass() + ! " does not support " + obj.getClass()); } ! validator.validate(obj, errors); if (logger.isDebugEnabled()) { if (errors.hasErrors()) { *************** *** 111,114 **** --- 109,113 ---- public static void rejectIfEmpty( Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) { + Object value = errors.getFieldValue(field); if (value == null || !StringUtils.hasLength(value.toString())) { *************** *** 144,147 **** --- 143,147 ---- public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, String defaultMessage) { + rejectIfEmptyOrWhitespace(errors, field, errorCode, null, defaultMessage); } *************** *** 162,165 **** --- 162,166 ---- public static void rejectIfEmptyOrWhitespace( Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage) { + Object value = errors.getFieldValue(field); if (value == null ||!StringUtils.hasText(value.toString())) { |