Announcement Announcement Module
No announcement yet.
Validator called before it is needed? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validator called before it is needed?

    Dear all,
    Probably this is a very naif question but I'm being around this problem for some hours now and I'm not able to see where's the error. I've a very simple FormController, FormValidator and the jsp form like:

    <bean name="/CreateAllocation.htm" class="administration.web.CreateAllocationController">
    <property name="sessionForm" value="true" />
    <property name="commandName" value="addAllocation" />
    <property name="commandClass" value="administration.service.AddAllocation" />
    <property name="validator">
    	<bean class="administration.service.AddAllocationValidator" />
    <property name="formView" value="/CreateAllocation" />
    <property name="successView" value="Home.htm" />
    	<property name="manager" ref="manager" />

    The AddAllocation class:

    public class AddAllocation {
        protected final Log logger = LogFactory.getLog(getClass());
        private float percentage;
        private float totalPercentage;
        public void setPercentage(float i) {
            percentage = i;
  "Percentage set to " + i);
        public float getPercentage() {
            return percentage;
        public float getTotalPercentage(){
        	return totalPercentage;

    The form controller:
    public class CreateAllocationController extends SimpleFormController  {
    	protected final Log logger = LogFactory.getLog(getClass());
    	private Manager manager;
    	public ModelAndView onSubmit(Object command) 
    			throws ServletException {
    		AddAllocation f = (AddAllocation) command;"returning from Create Allocation Form view to " + getSuccessView());
    		return new ModelAndView(new RedirectView(getSuccessView()));
    	protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    		AddAllocation addAllocation = new addAllocation();
    		return addAllocation;
    	public void setManager(Manager manager) {
    		this.Manager = manager;
    	public Manager getManager(){
    		return manager;

    The Validator

    public class AddAllocationValidator implements Validator {
        protected final Log logger = LogFactory.getLog(getClass());
    	public boolean supports(Class clazz) {
    		return clazz.equals(AddAllocation.class);
    	public void validate(Object command, Errors errors) {"Validating Form Add Allocation...");
    The jsp:
    <form:errors path="percentage" cssClass="error"/><br/>
    <form:form method="POST" commandName="addAllocation">
    <input type="submit" value="Submit">
    <form:input path="percentage"/>
    My problem with this example is that, when I load the CreateAllocation.htm page, it loads the Home.htm page automatically and, in the Tomcat console I get the:
     INFO: Validating Form Add Allocation... 
     INFO: returning from Create Allocation Form view to Home.htm
    what makes me think that vallidate method is called and so it is the onSubmit method of the controller.

    Any idea what I'm doing wrong?

    Thank you very much in advance for your time and help.