Results 1 to 3 of 3

Thread: MVC: Validation doesn't fire on form submission, but does upon returning to form.

  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Question MVC: Validation doesn't fire on form submission, but does upon returning to form.

    Hi,
    I'm using Spring MVC version 2.5.6.SEC01.
    I have a controller configured to use a validator when the form is submitted.
    Code:
    <bean name="debitCardLostStolenController"
    		class="aib.cctp.ui.controller.cards.DebitCardLostStolenController">	
    		<property name="sessionForm">
    			<value>true</value>
    		</property>		
    		<property name="commandClass">
    			<value>aib.cctp.domain.model.api.cards.DebitCardReplace</value>
    		</property>		
    		<property name="validator">
    			<ref bean="debitCardReplaceValidator"/>
    		</property>	
    </bean>
    However, when I submit the form, the validation is not kicking in. The webapp displays the next screen, which is a confirmation screen showing all the data entered on the input screen.
    The confirmation screen has a 'Back' button (<input> tag) that navigates back to the input screen by having
    Code:
    action="debitcardloststolen.htm?_target0=true" method="post"
    If I click the 'Back' button, I'm brought back to the input screen, but now the validation runs, and any validation errors appear on the input screen.

    Anyone got any ideas where I'm going wrong? This simple scenario is working fine on my other controllers. I'm sure it's something obvious, but I can't see it!
    Many thanks for your help,
    Ken.

  2. #2
    Join Date
    Apr 2006
    Posts
    166

    Default

    hi, you should post your controller and validation class here, is that abstractwizardformcontroller?

  3. #3
    Join Date
    Jun 2008
    Posts
    2

    Thumbs up Solution found.

    Hi,
    Managed to track it down. As I suspected it was a simple (and stupid) error; just one of those you can't see even though it's obvious. The wrong page number was specified in validatePage(...). The case value in the switch statement was set to 1, should have been 0. Grrr.
    Here's the correct code after I fixed the bug.
    Code:
    protected void validatePage(Object command, Errors errors, int page) {
    	switch (page) {
    		case 0:
    			getValidator().validate(command, errors);
    			break;
    	}
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •