AbstractWizardFormCOntroller Example

Spring Web MVC provides AbstractWizardFormController class that handle wizard form. In this tutorial, we will used AbstractWizardFormController class.

AbstractWizardFormCOntroller Example

AbstractWizardFormCOntroller Example

     

AbstractWizardFormCOntroller Example Part2.

we have configure the controller by set the bean properties with urlMapping like:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<
property name="interceptors">
<
list>
<
ref local="localeChangeInterceptor"/>
</
list>
</
property>
<
property name="urlMap">
<
map>
<entry key="/user1.html">
<
ref bean="wizardController"/>
</
entry>
</map>
</property>
</bean>

After that we have set bean for this controller and set class to handle request. we have also set commandName, commandClass, pages and pageAttribute properties like:

<bean id="wizardController" class="net.roseindia.web.AWizardFormController">
<
property name="commandName"><value>user</value></property><property name="commandClass"><value>net.roseindia.web.User</value></property>
<
property name="pages"><value>user1,user2,user3</value></property>
<property name="pageAttribute"><value>page</value></property>
</bean>

The pages property has a list of pages to participate in the wizard type application.

Step 4:

Now we will create three jsp files in the /WEB-INF/jsp/ folder. The user1.jsp and user2.jsp will have a form and some form field that accept user input and bind with the command object. The form will have two properties action and commandName. We will create three button and set name. the button name properties set the next and previous pages. The code of the user1.jsp is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@
taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@
taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@
taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<html>
<
head><title>First Entry</title></head>
<
body>
<
form:form method="POST" commandName="user">
<
center>
<
table>
<
tr>
<
td align="right" width="20%"> <strong>First Name:</strong></td>
<
td style="width: 20%">
<
spring:bind path="user.firstName">
<
input type="text" name="firstName" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="firstName"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Last Name:</strong></td>
<
td style="width: 20%">
<
spring:bind path="user.lastName">
<
input type="text" name="lastName" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="lastName"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Email Id:</strong></td>
<
td style="width: 40%">
<
spring:bind path="user.emailId">
<
input type="text" name="emailId" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="emailId"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Contact:</strong></td>
<
td style="width: 40%">
<
spring:bind path="user.contact">
<
input type="text" name="contact" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="contact"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Gender:</strong></td>
<
td style="width: 40%">
<
spring:bind path="user.gender">
<
input type="text" name="gender" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="gender"/></font>
</
td>
</
tr>
<
tr>
<
td ><strong></strong></td>
<
td colspan="2">
<
input type="submit" name="_cancel" value="Cancle"/>
<
input type="submit" name="_target1" value="Next"/>
<
input type="submit" name="_target2" value="Finish"/>
</
td>
</tr>
</
table>
</
center>
</
form:form>
</
body>
</
html>

The code of the user2.jsp is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@
taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@
taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@
taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<html>
<
head>
<
title>Second Entry</title>
</
head>
<
body>
<
form:form method="POST" commandName="user">
<
center>
<
table>
<
tr>
<
td align="right" width="20%"> <strong>Date of birth:</strong></td>
<
td style="width: 50%">
<
spring:bind path="user.dob">
<
input type="text" name="dob" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="dob"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Address:</strong></td>
<
td style="width: 50%">
<
spring:bind path="user.address">
<
input type="text" name="address" value="<c:out value="${status.value}"/>"/>
</
spring:bind>
</
td>
<
td><font color="red"><form:errors path="address"/></font>
</
td>
</
tr>
<
tr>
<
td align="right" width="20%"> <strong>Country:</strong></td>
<
td style="width: 50%">
<
spring:bind path="user.country">
<
input type="text" name="country" value="<c:out value="${status.value}"/>"/>

Back to Part 1