import org.springframework.validation.BindException;
import org.springframework.validation.ValidationUtils;
import org.springframework.web.bind.ServletRequestDataBinder;
...
//MultiAcitionController의 bindObject()를 다음과 같이 override한다.
protected BindException bindObject(HttpServletRequest request, Object command, Validator validator) throws Exception {
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
BindException errors = new BindException(command, getCommandName(command));
if (validator.supports(command.getClass())) {
ValidationUtils.invokeValidator(validator, command, errors);
}
return errors;
}
//Validator를 쓰고 싶은 부분에서,
BindException errors = bindObject(request, command, new XXXValidator());
if (errors.hasError()) {
mav.addAllObjects(errors.getModel());
return mav;
}
* mav = ModelAndView* command = validation 대상
* XXXValidator = 사용자가 만든 Validator 클래스
'Development > Java' 카테고리의 다른 글
| war 배포시 root context로 하려면? (0) | 2012.01.02 |
|---|---|
| JUnit에서의 예외 인식 (0) | 2010.08.04 |
| JUnit으로 test coverage를 높이는 습관 (0) | 2010.08.02 |
| Eclipse의 hashCode+equals VS. Apache의 HashCodeBuilder+EqualsBuilder (0) | 2010.06.21 |
| FindBugs - EQ_COMPARETO_USE_OBJECT_EQUALS 해결 (0) | 2010.06.21 |
| Eclipse에서 java 소스로부터 클래스 다이어그램을 쉽게 만들자/ eUML2 (0) | 2009.08.06 |
| javadoc과 package.html (0) | 2009.08.05 |
| Eclipse에서 javadoc을 pdf로 출력하기 (0) | 2009.08.05 |