2009-08-17 16 views

回答

0

根據MultiActionControlller API

考慮一個ServletRequestDataBinder的直接使用在你的控制器的方法,而不是依靠一個宣佈命令的說法。這允許完全控制整個活頁夾的設置和使用,包括驗證者的啓動和結合/驗證錯誤的後續評估。

所以,你可以使用

public class AddMultiActionController extends MultiActionController { 

    public AddMultiActionController() { 
     // Set up Valang according to your business requirement 
     // You can use xml settings instead 
     setValidators(new Validator [] {new CommandValidator(), new AnotherCommandValidator()}); 
    } 

    public ModelAndView addCommand(HttpServletRequest request, HttpServletResponse response) throws Exception { 
     Command command = new Command(); 

     // createBinder is a MultiActionController method 
     ServletRequestDataBinder binder = createBinder(request, command); 
     // Sets up any custom editor if necessary 
     binder.registerCustomEditor(...); 

     binder.bind(command); 

     return (!(binder.getErrors().hasErrors())) ? new ModelAndView("success") : new ModelAndView("failure"); 
    } 

    // similar approach as shown above 
    public ModelAndView addAnotherCommand(HttpServletRequest request, HttpServletResponse response) throws Exception { 
     AnotherCommand anotherCommand = new AnotherCommand(); 

     ... 
    } 
} 

問候,

相關問題