1 16 17 package org.springframework.web.bind; 18 19 import javax.servlet.ServletException ; 20 import javax.servlet.ServletRequest ; 21 22 import org.springframework.validation.BindException; 23 import org.springframework.validation.ValidationUtils; 24 import org.springframework.validation.Validator; 25 26 38 public abstract class BindUtils { 39 40 47 public static BindException bind(ServletRequest request, Object object, String objectName) { 48 ServletRequestDataBinder binder = new ServletRequestDataBinder(object, objectName); 49 binder.bind(request); 50 return binder.getErrors(); 51 } 52 53 64 public static BindException bind( 65 ServletRequest request, Object object, String objectName, 66 BindInitializer initializer) throws ServletException { 67 68 ServletRequestDataBinder binder = new ServletRequestDataBinder(object, objectName); 69 if (initializer != null) { 70 initializer.initBinder(request, binder); 71 } 72 binder.bind(request); 73 return binder.getErrors(); 74 } 75 76 85 public static BindException bindAndValidate( 86 ServletRequest request, Object object, String objectName, Validator validator) { 87 88 BindException binder = bind(request, object, objectName); 89 if (validator != null) { 90 ValidationUtils.invokeValidator(validator, object, binder); 91 } 92 return binder; 93 } 94 95 108 public static BindException bindAndValidate( 109 ServletRequest request, Object object, String objectName, 110 Validator validator, BindInitializer initializer) throws ServletException { 111 112 BindException binder = bind(request, object, objectName, initializer); 113 if (validator != null) { 114 ValidationUtils.invokeValidator(validator, object, binder); 115 } 116 return binder; 117 } 118 119 } 120 | Popular Tags |