2009-08-17 7 views

Répondre

0

Selon MultiActionControlller API

Tenir compte d'une utilisation directe ServletRequestDataBinder dans votre méthode de commande, au lieu de compter sur un argument de commande déclarée. Cela permet un contrôle total sur l'ensemble de la configuration et de l'utilisation du classeur, Y COMPRIS L'INVOCATION DES VALIDATEURS et l'ÉVALUATION SUBSÉQUENTE des erreurs de liaison/validation.

, vous pouvez utiliser

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(); 

     ... 
    } 
} 

salutations,

Questions connexes