You are on page 1of 5

AbstractWizardFormController -Spring

Description: web applications requires to display more than one


screen that a user interacts with in order to complete a given task.
This sequence of screens is called a "wizard." And this controller
allows you to carry the same command object through an entire flow of
Web pages, thus allowing you to break up the presentation into
multiple stages that act on the single model

Problem Description: A User registration process where the values are


captured from the user in more than one page, and on the confirmation
from the user for the values entered, the values are stored in the
database (Saving the values to the database is beyond the scope of
this document).The Screen shots of the same are as below

Page 1:

Page 2:

Page 3:

Next – Takes you to next page


Previous – Takes you to the previous page
Submit – Persist the data
Cancel – will take you back to the first page
Implementation:

Step 1: Configuring the spring main servlet (DispatcherServlet) in


web.xml

In the web.xml we have named the servlet as spring; hence the spring
context file is required to be named as spring-servlet.xml

Step 2: Configuring the Controller in spring-servlet.xml


The Controller provide by spring framework for the above discussed
scenario is AbstractWizardFormController, hence our controller
WizardController.java has to implement AbstractWizardFormController

The controller is required to override at least three methods as


defined below

• processCancel – the action that is required to be taken when


the cancel button is pressed, the name of the button in the jsp
file has to be “_cancel”
• processFinish – the action that is required to be taken when
the submit button is pressed, the name of the button in the jsp
page has to be “_submit”
• validatePage – The validations for the each and every page in
the wizard

Important Note: In the userinterface, as shown in the problem


description can have next button and the previous button. The order
of the pages that has to be appeared when they are clicked is defined
by the order in which they are set in the application context file,
for example

In the example shown above the order are form1, form2 and form3 and
the single model object that is associated with these forms is
User.java
form1.jsp

form2.jsp
form3.jsp

User.java

For more details contact me at santoshkothapalli@gmail.com or leave comment on


http://javacontractors.blogspot.com

Thank You,
Santosh Kothapalli SCWCD

You might also like