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 Part1.

AbstractWizardFormController example in Spring 2.5 Web MVC

Spring Web MVC provides AbstractWizardFormController class that handle wizard form. In this tutorial, we will used AbstractWizardFormController class. The AbstractWizardFormController class provide us to store and show the forms data with multiple pages. It manage the navigation between pages and validate the user input data form a single page of the whole model object at once. In this tutorial we will discuss about this controller.

Step 1:

Now we will create a index.jsp inside the WebContent folder. It will have a hyperlink "AbstractWizardFormController Test Application". If user click on this link request will generate. The code of the index.jsp is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<
head>
<
title>AbstractWizardFormController Example</title>
</
head>
<
body>
<
center>
<
a href="user1.html">
AbstractWizardFormController Test Application
</a><br/>
</center>
</
body>
</
html>

Step 2:

Now we will configured web.xml for DispatcherServlet and spring.tld. The code of the web.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<
web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns=
"http://java.sun.com/xml/ns/j2ee"

xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">
<
servlet>
<
servlet-name>dispatcher</servlet-name>
<
servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<
load-on-startup>1</load-on-startup>
</
servlet>
<
servlet-mapping>
<
servlet-name>dispatcher</servlet-name>
<
url-pattern>*.html</url-pattern>
</
servlet-mapping>
<
welcome-file-list>
<
welcome-file>index.jsp</welcome-file>
</
welcome-file-list>
<
taglib>
<
taglib-uri>/spring</taglib-uri>
<
taglib-location>/WEB-INF/spring.tld</taglib-location>
</
taglib>
</
web-app>

Step 3:

Now we will create dispatcher-servlet.xml file in the /WEB-INF/ folder. The dispatcher-servlet.xml file contain urlMapping, viewResolver for the all requests. we will configure the AWizardFormController for this application. User can see the code tin the dispatcher-servlet.xml file. the full code of the dispatcher-servlet.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http:
//www.springframework.org/schema/beans/spring-beans-2.5.xsd"

xmlns:p
="http://www.springframework.org/schema/p">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<
property name="prefix">
<
value>/WEB-INF/jsp/</value>
</
property>
<
property name="suffix">
<
value>.jsp</value>
</
property>
</
bean>
<
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>
<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>
<
bean id="localeChangeInterceptor" class=
"org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
>
<
property name="paramName" value="hl"/>
</
bean>
<bean id="localeResolver" class=
"org.springframework.web.servlet.i18n.SessionLocaleResolver"
/> </beans>

AbstractWizardFormCOntroller Example Part2.