Announcement Announcement Module
Collapse
No announcement yet.
MVC: Validation doesn't fire on form submission, but does upon returning to form. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    hi, you should post your controller and validation class here, is that abstractwizardformcontroller?

    Comment


    • #3
      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;
      	}
      }

      Comment

      Working...
      X