spring2.0,multiactioncontroller 일때 수동 validataion하기..(유지보수 프로젝트를 여행하는 히치하이커를 위한 안내서)

spring2.0  그리고 multiactioncontroller환경일때 수동으로 validation하는방법


in controller...

public  ModelAndView makePost(HttpServletRequest request,HttpServletResponse response) throws Exception{
Map model = new HashMap();
MakeCommand command = new MakeCommand();
bind(request, command);
BindingResult result = new BeanPropertyBindingResult( command, "command");

result.addError(new FieldError("row", "api_name", command.getApi_name(), false,null,null,"이름을 입력하세요"));
   
        //수동으로 BindingResult 추가 
        model.put("org.springframework.validation.BindingResult.command",result);
    if(result.hasErrors()){
    model.put("command",command);
    return new ModelAndView("apis/make",model);
    }
    
return new ModelAndView("apis/make",model);

}


in jsp...

<form:form action="${ctx }/apis/makePost.htm" method="post" commandName="command" >
api name
<form:input path="api_name" />
<form:errors path="api_name" />
        <input type="submit" value="save" /> 
</form:form>

댓글