Home Spring AbstractWizardFormCOntroller Example
Questions:Ask|Latest

Related Tutorials


 
 

Share on Google+Share on Google+

AbstractWizardFormCOntroller Example

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

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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 7, 2011

Related Tutorials

Ask Questions?    Discuss: AbstractWizardFormCOntroller Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
helen
June 4, 2011
Missing download code and files

Discuss: AbstractWizardFormCOntroller Example Could you send to me the download code and the rest part of tutorial start from user2.jsp file
Bahmad
August 25, 2012
the source code is missing

I find, the example for AbstractWizardFormCOntroller is very interesting. But the source code is missing. Can any one please get these.
anindita
October 17, 2011
AbstractWizardFormCOntroller complete Example

Could you send to me the download code of AbstractWizardFormController complete Example in my mail
vishnu
March 5, 2012
Code missing

I guess, the example for AbstractWizardFormCOntroller is not fully specified. And also the source code is missing. Can any one please get these.........
Umeshkumar
September 13, 2012
missing some code and download example link.

Hi, This Umesh. I am regular reader of roseindia.net. Almost all the solutions i found when i am learning some new technology or i am getting the work in any new technology which i am not aware with. I was going through all the Spring mvc 2.5 examples and I found that AbstractWizardformController is an incomplete example. I am aware that there are 2 parts of this example but 2nd example is not complete. user2.jsp needs some tags to be closed. and buttons should be added. user3.jsp should be there for summery. AWizardFormController class we mentioned into the dispatcher-servlet.xml is not specified. It also should be there. If i missed any otherthings missed in this example, sorry for that. Regards, Umeshkumar Fadadu
DMCA.com