I'm trying to figure out how the spring validators are called.
In the MVC tutorial it shows how to wire up a Validator and a Controller.
That seems to work fine, but I can't figure out how the validator gets called.
The relevent part of the config file is
Tracing through the Spring code, I think the validator gets called in the bindAndValidate method in BaseCommandController.Code:<!-- Validator and Form Controller for the "Price Increase" page --> <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/> <bean id="priceIncreaseForm" class="web.PriceIncreaseFormController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>priceIncrease</value></property> <property name="commandClass"><value>bus.PriceIncrease</value></property> <property name="validator"><ref bean="priceIncreaseValidator"/></property> <property name="formView"><value>priceincrease</value></property> <property name="successView"><value>hello.htm</value></property> <property name="productManager"> <ref bean="prodMan"/> </property> </bean>
As far as I can see isValidateOnBinding() will always return false, unless the validateOnBinding property is set to true in the confiig.Code:/** * Bind the parameters of the given request to the given command object. * @param request current HTTP request * @param command the command to bind onto * @return the ServletRequestDataBinder instance for additional custom validation * @throws Exception in case of invalid state or arguments */ protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command) throws Exception { ServletRequestDataBinder binder = createBinder(request, command); binder.bind(request); onBind(request, command, binder.getErrors()); if (this.validators != null && isValidateOnBinding() && !suppressValidation(request)) { for (int i = 0; i < this.validators.length; i++) { ValidationUtils.invokeValidator(this.validators[i], command, binder.getErrors()); } } onBindAndValidate(request, command, binder.getErrors()); return binder; }
What am I missing?


Reply With Quote