<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PermGen error &#187; ajax form</title>
	<atom:link href="http://eggsylife.co.uk/tag/ajax-form/feed/" rel="self" type="application/rss+xml" />
	<link>http://eggsylife.co.uk</link>
	<description>Eggsylife</description>
	<lastBuildDate>Mon, 18 Apr 2011 19:40:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Spring JS &#8211; Ajax Popup with list refresh</title>
		<link>http://eggsylife.co.uk/2010/11/08/spring-js-ajax-popup-with-list-refresh/</link>
		<comments>http://eggsylife.co.uk/2010/11/08/spring-js-ajax-popup-with-list-refresh/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 09:49:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax form]]></category>
		<category><![CDATA[list refresh]]></category>
		<category><![CDATA[partial rendering]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[spring 3]]></category>
		<category><![CDATA[spring js]]></category>
		<category><![CDATA[spring web flow]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=272</guid>
		<description><![CDATA[The concept I have been working with Spring-JS for a while now and have noticed that there doesn&#8217;t seem to be too many examples out there. This tutorial should hopefully address one common usage of Spring JS and its Ajax simplifications. One common use of any Ajax framework is to have a page list a [...]]]></description>
			<content:encoded><![CDATA[<div class="none"><div class="g-plusone" data-href="http://eggsylife.co.uk/2010/11/08/spring-js-ajax-popup-with-list-refresh/" size="medium" count="true"></div></div><h3>The concept</h3>
<p>I have been working with Spring-JS for a while now and have noticed that there doesn&#8217;t seem to be too many examples out there. This tutorial should hopefully address one common usage of Spring JS and its Ajax simplifications.</p>
<p>One common use of any Ajax framework is to have a page list a number of items. Then allow the user to add to those items. When adding an item a popup is displayed asking for the item details. Upon saving the item the popup is closed and the list underneath is refreshed. All actions working through Ajax and without changing page.</p>
<p>As a flow this would be:</p>
<ul>
<li>User clicks to list items</li>
<li>User clicks to add items</li>
<li>Popup displayed asking for new item details</li>
<li>User clicks save within popup</li>
<li>If new details passes validation</li>
<li>List of items refreshed and popup closed</li>
</ul>
<h3>Getting hold of the sample code</h3>
<p>I have hosted the completed project on GitHub. So please feel free to clone the repository @ git://github.com/eggsy84/SpringPopupRefreshList.git</p>
<p>Also if anyone has any contributions to add to the project please drop me an email or submit a request via GitHub for write access. The GitHub page is <a href="https://github.com/eggsy84/SpringPopupRefreshList" target="_blank">https://github.com/eggsy84/SpringPopupRefreshList</a>. You can also download the project from this site. The rest of the tutorial will continue assuming you have grabbed the source code.</p>
<h3>The servlet XML</h3>
<p>We firstly need to configure our <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html" target="_blank">Spring MVC</a> through the servlet-context.xml file. For Spring-JS and partial rendering to work we define the use of <a href="http://tiles.apache.org/" target="_blank">Apache Tiles as our view resolving</a> mechanism. We can do this by simply configuring a few beans:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;tilesConfigurer&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.tiles2.TilesConfigurer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;definitions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/tile-defs/tile-defs.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;viewClass&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.tiles2.TilesView&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The main item to note here is the location of our tile defintions file. This shall be discussed shortly. The final thing to add to the servlet-xml file is to tell <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-controller" target="_blank">Spring to context scan our project for Spring controllers</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- Enables the Spring MVC @Controller programming model --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;annotation-driven</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;uk.co.eggsylife.controller&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>We&#8217;re informing Spring to scan the &#8216;uk.co.eggsylife.controller&#8217; package. The <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml" target="_blank">complete servlet-context.xml</a> can be seen online.</p>
<h3>The configuration XML</h3>
<p>For the purpose of this tutorial, the application lists students and allows the user to add students. The &#8216;students&#8217; bean acts as an in-memory database that is added to at runtime. It is a simple <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html" target="_blank">Java ArrayList</a> of Student model objects. Typically you will have your own model objects and different <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete" target="_blank">CRUD operations</a> on those objects.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;students&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;java.util.ArrayList&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;uk.co.eggsylife.persistent.Student&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentNumber&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;John&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Smith&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;uk.co.eggsylife.persistent.Student&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentNumber&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Jane&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Smith&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Within the application when a Student is added we also validate the details entered. A simple <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/java/uk/co/eggsylife/validation/StudentValidator.java" target="_blank">Student Validator</a> is created and referenced from the configuration XML.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;studentValidator&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;uk.co.eggsylife.validation.StudentValidator&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Finally we tell Spring the location of our ValidationMessages message properties file. If the user enter any details incorrectly we can raise an error for the field entered and specify a message code for the error. Spring will then look up that message code from the <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/resources/ValidationMessages.properties" target="_blank">ValidationMessages.properties</a> file</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;messageSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.context.support.ReloadableResourceBundleMessageSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;basenames&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>classpath:ValidationMessages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cacheSeconds&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>60<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/spring/app-config.xml" target="_blank">app-config is now completed</a>.</p>
<h3>Tiles setup and JSP file</h3>
<p>Earlier in the tutorial we referenced the location of the Tile definitions, &#8216;/WEB-INF/tile-defs/tile-defs.xml&#8217;. This file declares all the views the web application uses and is crucial to making Spring JS and partial rendering function correctly.</p>
<p>Firstly we define an overall template that can be be used for any views our application requires. Declaring a template allows you to re-use the styling across multiple views.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;template.view&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/templates/template.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/blank.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The &#8216;template.jsp&#8217; file is pretty basic. It simple declares the HTML headers. Each time we change the &#8216;content&#8217; of this Tile definition it will continue to be surrounded by the markup on the template.jsp.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
        &lt;head&gt;
                &lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/dojo/dojo.js&quot; /&gt;&quot;&gt; &lt;/script&gt;
                &lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/spring/Spring.js&quot; /&gt;&quot;&gt; &lt;/script&gt;
                &lt;script type=&quot;text/javascript&quot; src=&quot;&lt;c:url value=&quot;/resources/spring/Spring-Dojo.js&quot; /&gt;&quot;&gt; &lt;/script&gt;
                &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;&lt;c:url value='/resources/dijit/themes/tundra/tundra.css' /&gt;&quot; /&gt;
&nbsp;
                &lt;title&gt;Spring-JS Edit Dialog and Partial JS Example&lt;/title&gt;
&nbsp;
        &lt;/head&gt;
&nbsp;
        &lt;body class=&quot;tundra&quot;&gt;
&nbsp;
                &lt;p&gt;Spring Edit Dialog and Partial Content Update Tutorial&lt;/p&gt;
&nbsp;
                &lt;tiles:insertAttribute name=&quot;content&quot; /&gt;
        &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>This means that every page will have the title set as above and every page will have the &#8216;Spring Edit&#8230;..&#8217; paragraph present. Also note we are including the various Spring required Javascript files. By default they are located in the /resources/ folder of the web application. They are required in order to make Spring-JS Ajax functions work.</p>
<p>In this example I have also included the Dojo Tundra theme to improve the look and feel of the sample application but this is by no means required.</p>
<p>The tutorial only has one screen which lists students and should look similar to figure 1.</p>
<div id="attachment_313" class="wp-caption aligncenter" style="width: 160px"><a href="http://eggsylife.co.uk/wp-content/uploads/2010/11/studentsList.jpg"><img src="http://eggsylife.co.uk/wp-content/uploads/2010/11/studentsList-150x150.jpg" alt="" title="studentsList" width="150" height="150" class="size-thumbnail wp-image-313" /></a><p class="wp-caption-text">Figure 1</p></div>
<p>This screen simply lists the students and provides a link for the user to add a new student. When a new student is added we don&#8217;t navigate away from the page we simply append the student to the bottom of the list.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;students.view&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;template.view&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;studentsList.view&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentsList.view&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/students.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentsList&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/studentList.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentEditDialog&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/util/dialogClose.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We firstly declare the overall &#8216;students.view&#8217; which extends our default template as mentioned earlier. This view is actually a template itself and requires two entries &#8211; a list of students and a student edit dialog. The &#8216;students.jsp&#8217; file is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ include file=&quot;/WEB-INF/pages/include.jsp&quot; %&gt;
&nbsp;
&lt;tiles:insertAttribute name=&quot;studentsList&quot; /&gt;
&nbsp;
&lt;tiles:insertAttribute name=&quot;studentEditDialog&quot; /&gt;</pre></div></div>

<p>The &#8216;students.jsp&#8217; doesn&#8217;t contain much other than the inclusion of the two areas of content. &#8216;studentList&#8217; and &#8216;studentEditDialog&#8217;. First of all lets look at the &#8216;studentList.jsp&#8217; file which we inject into the &#8216;studentsList&#8217; attribute.</p>

<div class="wp_syntax"><div class="code"><pre class="html4" style="font-family:monospace;">&lt;%@ include file=&quot;/WEB-INF/pages/include.jsp&quot; %&gt;
&nbsp;
&nbsp;
&lt;div id=&quot;studentsList&quot;&gt;
	&lt;table border=&quot;1&quot; width=&quot;600px&quot;&quot;&gt;
		&lt;thead&gt;
			&lt;tr&gt;
				&lt;th width=&quot;33%&quot; align=&quot;left&quot;&gt;
					Student ID
				&lt;/th&gt;
				&lt;th width=&quot;33%&quot; align=&quot;left&quot;&gt;
					First name
				&lt;/th&gt;
				&lt;th width=&quot;33%&quot; align=&quot;left&quot;&gt; 
					Last name
				&lt;/th&gt;
			&lt;/tr&gt;
		&lt;/thead&gt;
		&lt;tbody&gt;
			&lt;c:forEach var=&quot;student&quot; items=&quot;${students}&quot;&gt;
				&lt;tr&gt;
					&lt;td&gt;
						${student.studentNumber}
					&lt;/td&gt;
					&lt;td&gt;
						${student.firstName}
					&lt;/td&gt;
					&lt;td&gt;
						${student.lastName}
					&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/c:forEach&gt;
		&lt;/tbody&gt;
	&lt;/table&gt;
&nbsp;
	&lt;a href=&quot;&lt;c:url value='/students/edit' /&gt;&quot; id=&quot;createStudentLink&quot;&gt;
		Create new student
	&lt;/a&gt;
&nbsp;
	&lt;script type=&quot;text/javascript&quot;&gt;
		dojo.addOnLoad(function() {
			Spring.addDecoration(new Spring.AjaxEventDecoration({
				elementId: &quot;createStudentLink&quot;,
				event: &quot;onclick&quot;,
				popup:true,
				params: {fragments: &quot;studentsList, studentEditDialog&quot;}
			}));
		});
	&lt;/script&gt;
&nbsp;
&lt;/div&gt;</pre></div></div>

<p>The view simply lists each student in a table and provides a link to be able to add students. There are two main things to note on this JSP. Firstly notice that it is wrapped in a &#8216;DIV&#8217; element with the same id as the tiles attribute defintion, &#8216;studentsList&#8217;. This is crucial to making Spring partial refresh work. Also note the way in which we &#8216;decorate&#8217; the &#8216;Create new student&#8217; link with Spring Javascript.</p>
<p>Firstly we declare the &#8216;dojo.addOnLoad&#8217; function. This means that this piece of Javascript will execute when the page loads. Next we use the &#8216;Spring.addDecoration&#8217; method to add the Ajax decorations. This function takes a number of parameters. Firstly the &#8216;elementId&#8217; This is the id of the element that we attach the decoration to. In this case we are attaching the decoration to the &#8216;Create new student&#8217; link. The event is then specified. We want the Ajax actions to run when the link is clicked so we specify the &#8216;onclick&#8217; event. Next we set the &#8216;popup&#8217; variable to &#8216;true&#8217;. This means that whatever the response is we want it rendered as a popup dialog.</p>
<p>The final parameter is &#8216;fragments&#8217;. This identifies which areas of content we want refresh. We state that we want both the &#8216;studentsList&#8217; and the &#8216;studentEditDialog&#8217; updated. Notice the names match our tiles attributes and that we wrap the &#8216;studentsList.jsp&#8217; in a DIV with the id of &#8216;studentsList&#8217;. This way Spring knows how to identify content and replace it.</p>
<p>Now lets look at the &#8216;studentEditDialog&#8217; content. In this instance we are injecting a utility JSP file that closes any open dialogs. The JSP is basically a bit of Javascript that closes any open Dojo popup dialogs. When first listing the students it is not particularly useful as we haven&#8217;t got any open dialogs. However when we save a new student a redirect to the students list view the JSP&#8217;s use will become clear.</p>

<div class="wp_syntax"><div class="code"><pre class="html4" style="font-family:monospace;">&lt;!-- This is a utility JSP that closes any Dojo Modal dialogs --&gt;
&lt;script type=&quot;text/javscript&quot;&gt;
dojo.query(&quot;.dijitDialog&quot;).forEach(function(element) {
	dijit.byId(element.id).hide();
});
&lt;/script&gt;</pre></div></div>

<p>The last tile definition is the view that contains our full student edit dialog. The dialog allows users to create a new student, asking for the student name and id number.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentsListAndEditDialog.view&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;studentsList.view&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentsList&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/blank.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;put-attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;studentEditDialog&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/WEB-INF/pages/studentEditDialog.jsp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The only difference with this definition is the that we switch out the &#8216;dialogClose.jsp&#8217; with the actual student edit dialog. The student edit dialog is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="html5" style="font-family:monospace;">&lt;%@ include file=&quot;/WEB-INF/pages/include.jsp&quot; %&gt;
&nbsp;
&nbsp;
&lt;div id=&quot;studentEditDialog&quot;&gt;
	&lt;p&gt;Student Edit Dialog&lt;/p&gt;
&nbsp;
	&lt;form:form id=&quot;studentForm&quot; modelAttribute=&quot;student&quot;&gt;
		&lt;table&gt;
			&lt;tr&gt;
				&lt;td&gt;Student number&lt;/td&gt;
				&lt;td&gt;
					&lt;form:input path=&quot;studentNumber&quot; /&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
				&lt;td&gt;First name&lt;/td&gt;
				&lt;td&gt;
					&lt;form:input path=&quot;firstName&quot; /&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
				&lt;td align=&quot;center&quot; colspan=&quot;2&quot; style=&quot;color: red; font-size: 0.8em;&quot;&gt;
					&lt;form:errors path=&quot;firstName&quot; /&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
				&lt;td&gt;Last name&lt;/td&gt;
				&lt;td&gt;
					&lt;form:input path=&quot;lastName&quot; /&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
				&lt;td align=&quot;center&quot; colspan=&quot;2&quot; style=&quot;color: red; font-size: 0.8em;&quot;&gt;
					&lt;form:errors path=&quot;lastName&quot; /&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;
		&lt;input type=&quot;submit&quot; id=&quot;saveStudentButton&quot; value=&quot;Save student&quot; /&gt;
	&lt;/form:form&gt;
&nbsp;
	&lt;script type=&quot;text/javascript&quot;&gt;
		dojo.addOnLoad(function() {
				Spring.addDecoration(new Spring.AjaxEventDecoration({
    				elementId:'saveStudentButton', 
    				event:'onclick',
    				formId:'studentForm',
    				params: {fragments: &quot;studentsList,studentEditDialog&quot;}
    			}));
		});
	&lt;/script&gt;
&lt;/div&gt;</pre></div></div>

<div id="attachment_315" class="wp-caption aligncenter" style="width: 160px"><a href="http://eggsylife.co.uk/wp-content/uploads/2010/11/popup.jpg"><img src="http://eggsylife.co.uk/wp-content/uploads/2010/11/popup-150x150.jpg" alt="" title="studentPopupDialog" width="150" height="150" class="size-thumbnail wp-image-315" /></a><p class="wp-caption-text">Figure 2</p></div>
<p>Again, notice we wrap the content in a DIV element with the same id as our tiles attribute, &#8216;studentEditDialog&#8217;. We then go on to declare a <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring-form.tld.html" target="_blank">Spring form</a>. For now I won&#8217;t go on to discuss the Spring MVC and form bindings. Finally note we attach the Spring decorations again. The only difference is this time we specify a form id and remove the popup attribute. We attach the code to the &#8216;Save student&#8217; button which is the submit button for the &#8216;studentForm&#8217;. This means that we want our Ajax events to be actioned when the form is submitted.</p>
<p>That concludes our view definitions. The <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/tile-defs/tile-defs.xml" target="_blank">tiles-defs.xml</a>, <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/pages/students.jsp" target="_blank">students.jsp</a>, <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/pages/studentList.jsp" target="_blank">studentsList.jsp</a>, <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/pages/util/dialogClose.jsp" target="_blank">dialogClose.jsp</a> and <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/webapp/WEB-INF/pages/studentEditDialog.jsp" target="_blank">studentEditDialog.jsp</a>.</p>
<h3>Java Controllers</h3>
<p>The tutorial only has one controller. The &#8216;StudentController&#8217; handles the three primary functions of the application. It handles the showing of the students list (GET), the showing of the edit dialog (GET) and the adding of a student (POST). </p>
<p>The list of students is handled by the &#8216;showStudentsList&#8217; method.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> STUDENTS_VIEW_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;students.view&quot;</span><span style="color: #339933;">;</span>
&nbsp;
@Autowired
<span style="color: #000000; font-weight: bold;">protected</span> ArrayList<span style="color: #339933;">&lt;</span>Student<span style="color: #339933;">&gt;</span> students <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span>
&nbsp;
&nbsp;
@RequestMapping<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/students&quot;</span>, method<span style="color: #339933;">=</span>RequestMethod.<span style="color: #006633;">GET</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> showStudentsList<span style="color: #009900;">&#40;</span>ModelMap modelMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	modelMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;students&quot;</span>, students<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> STUDENTS_VIEW_KEY<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It simply adds our list of students to the view and returns the &#8216;students.view&#8217; tile definition. The list of students is Autowired from our Spring app-config file as defined earlier. It is wired to handle the URL &#8216;/students&#8217;.</p>
<p>Secondly there is the &#8216;showStudentEditForm&#8217; method. This handles the URL &#8216;/students/edit&#8217; and is called when the user clicks the &#8216;Create new student&#8217; link.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> STUDENT_EDIT_DIALOG_VIEW_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;studentsListAndEditDialog.view&quot;</span><span style="color: #339933;">;</span>
&nbsp;
@RequestMapping<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/students/edit&quot;</span>, method<span style="color: #339933;">=</span>RequestMethod.<span style="color: #006633;">GET</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> showStudentEditForm<span style="color: #009900;">&#40;</span>ModelMap modelMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Object class will be used as our</span>
	<span style="color: #666666; font-style: italic;">// form backing object</span>
	Student student <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Student<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	modelMap.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student&quot;</span>, student<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">return</span> STUDENT_EDIT_DIALOG_VIEW_KEY<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It returns the &#8216;studentsListAndEditDialog.view&#8217; and adds a new &#8216;Student&#8217; object to the view for our form. This object is used as the form backing object. The Student object is a POJO and will be seen later. Finally we have the &#8216;saveStudentEdit&#8217; method that is actioned when the form is submitted. If the form is submitted without errors then it simply returns the same view as the listing of the students. If the user submits the form and it contains errors then it returns the edit form view with details of the error.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
@Autowired
<span style="color: #000000; font-weight: bold;">protected</span> StudentValidator studentValidator <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
@RequestMapping<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/students/edit&quot;</span>, method<span style="color: #339933;">=</span>RequestMethod.<span style="color: #006633;">POST</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> saveStudentEdit<span style="color: #009900;">&#40;</span>@ModelAttribute Student student, BindingResult errors, ModelMap modelMap<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	studentValidator.<span style="color: #006633;">validate</span><span style="color: #009900;">&#40;</span>student, errors<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> errors.<span style="color: #006633;">hasErrors</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> STUDENT_EDIT_DIALOG_VIEW_KEY<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		students.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>student<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		modelMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;students&quot;</span>, students<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> STUDENTS_VIEW_KEY<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice if the form doesn&#8217;t have errors we add the student object back into the collection of students and update the list of students in the view. This is important so that the list of students is updated with the student that has just been added. The utility JSP that closes any open Dojo modal dialogs now comes into full use as it makes sure that the edit student dialog is closed after a student has been successfully added. The method responds to the POST request method so it is actioned when our form is &#8216;POSTED&#8217;. The complete <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/java/uk/co/eggsylife/controller/StudentController.java" target="_blank">StudentController</a> includes all the above methods.</p>
<h3>The Validator and Student POJO</h3>
<p>To wrap things up the final two Java classes the application uses is the <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/java/uk/co/eggsylife/validation/StudentValidator.java" target="_blank">StudentValidator</a> and the POJO <a href="https://github.com/eggsy84/SpringPopupRefreshList/blob/master/src/main/java/uk/co/eggsylife/persistent/Student.java" target="_blank">Student</a> object.</p>
<p>The validator simply checks that the user has entered both a first name and last name. The Student object encapsulates items a student has.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StudentValidator <span style="color: #000000; font-weight: bold;">implements</span> Validator <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#supports(java.lang.Class)
	 */</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> supports<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> Student.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>clazz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */</span>
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> validate<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> obj, Errors errors<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Student student <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Student<span style="color: #009900;">&#41;</span>obj<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> student.<span style="color: #006633;">getFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> student.<span style="color: #006633;">getFirstName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			errors.<span style="color: #006633;">rejectValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;firstName&quot;</span>, <span style="color: #0000ff;">&quot;student.first.name.empty&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> student.<span style="color: #006633;">getLastName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> student.<span style="color: #006633;">getLastName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			errors.<span style="color: #006633;">rejectValue</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;lastName&quot;</span>, <span style="color: #0000ff;">&quot;student.last.name.empty&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Student <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> studentNumber <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> firstName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> lastName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getStudentNumber<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> studentNumber<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStudentNumber<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> studentNumber<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">studentNumber</span> <span style="color: #339933;">=</span> studentNumber<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> firstName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFirstName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> firstName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">firstName</span> <span style="color: #339933;">=</span> firstName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> lastName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastName</span> <span style="color: #339933;">=</span> lastName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Conclusion</h3>
<p>That should have gave you a complete example on how to use Spring-JS alongside Spring MVC and perform partial refresh of the content. The key to understanding the tutorial is understanding the tie between between the tiles defintions, the identified DIV elements and the usage of Javascript to link the two together.</p>
<p>The project can be <a href="https://github.com/eggsy84/SpringPopupRefreshList/zipball/master" target="_blank">downloaded as a Zip</a> from <a href="http://www.github.com" target="_blank">GitHub</a>. For those familiar with Git you can also get the project from the Git Repository under the URL &#8216;git://github.com/eggsy84/SpringPopupRefreshList.git&#8217;. If anyone would like to comment or have anything to contribute to the codebase please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2010/11/08/spring-js-ajax-popup-with-list-refresh/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Spring Forms, Dynamic Lists and Ajax</title>
		<link>http://eggsylife.co.uk/2009/11/30/spring-forms-dynamic-lists-and-ajax/</link>
		<comments>http://eggsylife.co.uk/2009/11/30/spring-forms-dynamic-lists-and-ajax/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 09:11:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax form]]></category>
		<category><![CDATA[dynamic lists]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring annotations]]></category>
		<category><![CDATA[spring form]]></category>
		<category><![CDATA[spring mvc annotations]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=183</guid>
		<description><![CDATA[Spring Forms and Dynamic Binding Lists Introduction After my recent posts on Spring forms and annotations &#8211; dynamic lists is logically another step to be discussed. In the previous examples we use a form backing object &#8211; the form backing objects have tended to be very basic and primitive Using dynamic lists within these objects [...]]]></description>
			<content:encoded><![CDATA[<div class="none"><div class="g-plusone" data-href="http://eggsylife.co.uk/2009/11/30/spring-forms-dynamic-lists-and-ajax/" size="medium" count="true"></div></div><h2>Spring Forms and Dynamic Binding Lists</h2>
<p><strong>Introduction</strong></p>
<p>After my <a href="http://eggsylife.co.uk/2009/11/06/spring-annotations-and-forms/" target="_blank">recent posts on Spring forms and annotations</a> &#8211; dynamic lists is logically another step to be discussed.</p>
<p>In the previous examples we use a form backing object &#8211; the form backing objects have tended to be very basic and primitive</p>
<p>Using dynamic lists within these objects makes them slightly more complicated. Suppose the following scenario:</p>
<p><strong>Class enrolment example</strong></p>
<ul>
<li>User chooses to create a new class</li>
<li>User types in class name</li>
<li>User also has to specify one (or many) names of students in the class</li>
</ul>
<p>Using that scenario you can imagine a form in which there is a class name field and then below that a simple student name field. When the user clicks add next to the student name &#8211; javascript should simply show another input field for a student name allowing a user to add one or more students.</p>
<p>Eventually when the form gets submitted to the server a list of students will be populated.</p>
<p>However if we don&#8217;t using Spring&#8217;s dynamic lists &#8211; specifically Spring&#8217;s AutoPopulatingList &#8211; we cannot perform such an action as we have out of bounds errors.</p>
<p><strong>Configuring your build environment</strong></p>
<p>Your workspace needs setting up as the previous examples. Using Eclipse create a new project. For your src directory enter the value /WEB-INF/src. For your output directory use the WEB-INF/classes directory.</p>
<p>Add a new lib directory in your WEB-INF folder. Under your WEB-INF directoy you will need the following JAR files (all of which can be obtained from the <a href="http://www.springsource.org/" target="_blank">Spring download</a>). Add the jars to your buildpath.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">commons<span style="color: #339933;">-</span>beanutils.<span style="color: #006633;">jar</span>
commons<span style="color: #339933;">-</span>collections.<span style="color: #006633;">jar</span>
jstl.<span style="color: #006633;">jar</span>
spring<span style="color: #339933;">-</span>core.<span style="color: #006633;">jar</span>
spring<span style="color: #339933;">-</span>webmvc.<span style="color: #006633;">jar</span>
spring.<span style="color: #006633;">jar</span>
standard.<span style="color: #006633;">jar</span>
tiles<span style="color: #339933;">-</span>api<span style="color: #339933;">-</span>2.0.6.<span style="color: #006633;">jar</span>
tiles<span style="color: #339933;">-</span>core<span style="color: #339933;">-</span>2.0.6.<span style="color: #006633;">jar</span>
tiles<span style="color: #339933;">-</span>jsp<span style="color: #339933;">-</span>2.0.6.<span style="color: #006633;">jar</span></pre></div></div>

<p>Next add the Spring servlet.xml to your application. Create a file called dynamiclists-servlet.xml in your WEB-INF folder. Add the following to the file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:p</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/p&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:context</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/context&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans </span>
<span style="color: #009900;">                           http://www.springframework.org/schema/beans/spring-beans.xsd</span>
<span style="color: #009900;">                           http://www.springframework.org/schema/context </span>
<span style="color: #009900;">                           http://www.springframework.org/schema/context/spring-context.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
&nbsp;
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;com.annotations.controller&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Enables plain Controllers --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;tilesConfigurer&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.tiles2.TilesConfigurer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;definitions&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/tiles-defs/templates.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewResolver&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;viewClass&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.view.tiles2.TilesView&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>                
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Next add your web.xml in the same location as your Spring servlet.xml file. Add the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.4&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">		 <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Spring Dynamic Lists Example<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/display-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>dynamiclists<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.springframework.web.servlet.DispatcherServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>dynamiclists<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.page<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Next add a new folder in your WEB-INF directory called tiles-defs and add a file called templates.xml within that. Add the following to the templates.xml file</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE tiles-definitions PUBLIC</span>
<span style="color: #00bbdd;">       &quot;-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN&quot;</span>
<span style="color: #00bbdd;">       &quot;http://tiles.apache.org/dtds/tiles-config_2_0.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tiles-definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;form.view&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/pages/form.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;formStudentInsert.view&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/pages/formStudentInsert.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definition</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;formResult.view&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/pages/formResult.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definition<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tiles-definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That should be the workspace setup &#8211; next to create our form JSP pages</p>
<p><strong>Form JSP pages and a touch of jQuery</strong></p>
<p>Firstly create a new folder under your application called js. Next <a href="http://docs.jquery.com/Downloading_jQuery" target="_blank">download jQuery</a> and place the jQuery download within the folder.</p>
<p>Under your project create a new folder names pages and create a file named form.jsp within that.This will be our class creation form.</p>
<p>Add the following to your form.jsp file</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;form&quot; uri=&quot;http://www.springframework.org/tags/form&quot; %&gt;
&lt;%@ taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot; %&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot; src=&quot;/dynamiclists/js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
	var studentPosition = 0;
	$(&quot;#addStudentButton&quot;).click(function() {
		studentPosition++;
&nbsp;
		$.get(&quot;&lt;%=request.getContextPath()%&gt;/appendStudentView.page&quot;, { fieldId: studentPosition},
			function(data){
				$(&quot;#submitRow&quot;).before(data);
		});
	});
});
&lt;/script&gt;
&nbsp;
&lt;form:form method=&quot;post&quot; name=&quot;classForm&quot; id=&quot;classForm&quot; commandName=&quot;classCommand&quot;&gt;
	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;Class Name:&lt;/td&gt;
			&lt;td colspan=&quot;2&quot;&gt;&lt;form:input path=&quot;className&quot; size=&quot;40&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td colspan=&quot;3&quot;&gt;&lt;strong&gt;Students&lt;/strong&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Student name&lt;/td&gt;
			&lt;td&gt;
				&lt;spring:bind path=&quot;classCommand.students[0].studentName&quot;&gt;
					&lt;form:input path=&quot;${status.expression}&quot; size=&quot;40&quot; /&gt;
	  			&lt;/spring:bind&gt;
			&lt;/td&gt;
			&lt;td&gt;&lt;input type=&quot;button&quot; id=&quot;addStudentButton&quot; value=&quot;Add&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr id=&quot;submitRow&quot;&gt;
			&lt;td&gt;&amp;nbsp;&lt;/td&gt;
			&lt;td&gt;&lt;input type=&quot;submit&quot; value=&quot;Save Class&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
&lt;/form:form&gt;</pre></div></div>

<p>This probably requires a bit of an explanation. The first two lines of the file include the required Spring tag libraries.</p>
<p>After that we include the link to our downloaded jQuery Javascript source. I&#8217;ll make an assumption that people are familiar with jQuery.</p>
<p>Next we use <a href="http://docs.jquery.com/Events/click#fn" target="_blank">jQuery to add a click event listener</a> to our form &#8216;Add&#8217; button. When the user clicks add button we fire off an <a href="http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype" target="_blank">Ajax Get request</a> to our server which sends an incremented number as part of its data string. This Ajax request hits our server which simply <a href="http://docs.jquery.com/Manipulation/before#content" target="_blank">appends a new row</a> to the form for another student name. We use the number for the index number in the collection of students.</p>
<p>The response is simply appended as a new row in our form before the form submit button. After that Javascript the rest is a basic Spring form.</p>
<p>Next create a new file called formStudentInsert.jsp in the same location as your form.jsp and add the following contents.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;form&quot; uri=&quot;http://www.springframework.org/tags/form&quot; %&gt;
&lt;%@ taglib uri=&quot;http://www.springframework.org/tags&quot; prefix=&quot;spring&quot; %&gt;
&nbsp;
&lt;tr&gt;
	&lt;td&gt;&amp;nbsp;&lt;/td&gt;
	&lt;td&gt;
		&lt;form:input path=&quot;classCommand.students[${studentNumber}].studentName&quot; size=&quot;40&quot; /&gt;
	&lt;/td&gt;
	&lt;td&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;</pre></div></div>

<p>As mentioned before this is JSP that gets appended to our form when we send the Ajax request.</p>
<p>The form should look similar to the image below.</p>
<p><a href="http://eggsylife.co.uk/wp-content/uploads/2009/11/class_form.jpg"><img src="http://eggsylife.co.uk/wp-content/uploads/2009/11/class_form-150x150.jpg" alt="Picture of class form" title="Class Form" width="150" height="150" class="size-thumbnail wp-image-186" /></a></p>
<p>Next create a JSP page that is displayed when the user submits the form. Create a new JSP called formResult.jsp and add the following contents.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
&nbsp;
&lt;h2&gt;Class ${savedClass.className}&lt;/h2&gt;
&nbsp;
&lt;p&gt;Students&lt;/p&gt;
&nbsp;
&lt;ul&gt;
	&lt;c:forEach var=&quot;student&quot; items=&quot;${savedClass.students}&quot;&gt;
		&lt;li&gt;${student.studentName}&lt;/li&gt;
	&lt;/c:forEach&gt;
&lt;/ul&gt;</pre></div></div>

<p><strong>The Form Backing Object</strong></p>
<p>We next need to create the form backing objects that will be used for this example. Create a new Java class called Student and add the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author Eggsy - eggsy _at_ eggsylife.co.uk
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Student<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> studentName <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getStudentName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> studentName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStudentName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> studentName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">studentName</span> <span style="color: #339933;">=</span> studentName<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This class is a simple Student object. Student objects will belong to a class object. Now we can go ahead and create the Class object.</p>
<p>Create a new class called ClassCommand and add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.util.AutoPopulatingList</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author Eggsy - eggsy _at_ eggsylife.co.uk
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ClassCommand <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> className <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> AutoPopulatingList students <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getClassName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> className<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setClassName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> className<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">className</span> <span style="color: #339933;">=</span> className<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> AutoPopulatingList getStudents<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> students<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setStudents<span style="color: #009900;">&#40;</span>AutoPopulatingList students<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">students</span> <span style="color: #339933;">=</span> students<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The class command object is the backing object we shall use for our form. It simply has a class name. However it does also have a list of students. For this we could have used a basic java.util.ArrayList but this causes issues when attempting to bind the form. As the list wouldn&#8217;t (initially) have any contents we would experience IndexOutOfBounds exception messages. This is where we can use the incredibly helpful <a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/util/AutoPopulatingList.html" target="_blank">Spring AutopopulatingList</a>.</p>
<p><strong>Spring Annotated Form Controller</strong></p>
<p>Finally we need to create the Spring Form controller that handles our various requests. Note in the servlet XML file we specified that we would scan the package com.annotations.controller package for controller annotations. Go ahead and create this package. (You can of course change this). Now create a class called ClassFormController containing the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.stereotype.Controller</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.ui.ModelMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.util.AutoPopulatingList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.ModelAttribute</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestMapping</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestMethod</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.bind.annotation.RequestParam</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.annotations.command.ClassCommand</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.annotations.command.Student</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author Eggsy - eggsy _at_ eggsylife.co.uk
 */</span>
@Controller
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ClassFormController
<span style="color: #009900;">&#123;</span>
&nbsp;
	@ModelAttribute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;classCommand&quot;</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #000000; font-weight: bold;">public</span> ClassCommand getClassCommand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
		ClassCommand classCommand <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassCommand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		classCommand.<span style="color: #006633;">setStudents</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AutoPopulatingList<span style="color: #009900;">&#40;</span>Student.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> classCommand<span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * &lt;p&gt;Called when the form is initially displayed&lt;/p&gt;
	 * @param model
	 * @return
	 */</span>
	@RequestMapping<span style="color: #009900;">&#40;</span>method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">GET</span>, value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/processClassForm.page&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> showNameForm<span style="color: #009900;">&#40;</span>ModelMap model<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>	
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;form.view&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * &lt;p&gt;Called when the user clicks the add button&lt;/p&gt;
	 * @param fieldId
	 * @param model
	 * @return
	 */</span>
	@RequestMapping<span style="color: #009900;">&#40;</span>method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">GET</span>, value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/appendStudentView.page&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> appendStudentField<span style="color: #009900;">&#40;</span>@RequestParam <span style="color: #003399;">Integer</span> fieldId, ModelMap model<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>	
		model.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;studentNumber&quot;</span>, fieldId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;formStudentInsert.view&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * &lt;p&gt;Called when the user finally submits the class form&lt;/p&gt;
	 * @param classCommand
	 * @param model
	 * @return
	 */</span>
	@RequestMapping<span style="color: #009900;">&#40;</span>method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">POST</span>, value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/processClassForm.page&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> onSubmit<span style="color: #009900;">&#40;</span> @ModelAttribute<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;classCommand&quot;</span><span style="color: #009900;">&#41;</span> ClassCommand classCommand,  ModelMap model <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		model.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;savedClass&quot;</span>, classCommand<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;formResult.view&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;ll assume you&#8217;re comfortable with <a href="http://eggsylife.co.uk/2009/11/06/spring-annotations-and-forms/" target="_blank">Spring annotations</a> so I&#8217;ll just highlight the important parts. Firstly notice the way we declare our ClassCommand object. We new up the object then set the Students list as a new AutoPopulatingList of type Student.class. This is again so that we can ensure we experience no IndexOutOfBounds errors. The next method is called when we display our form simply returning the form.view. After that we have the method that gets called when the user clicks the Add button. This returns the small HTMl snippet that gets appended to our form. Finally we have the onSubmit method that gets called when we submit our form and returns the formResult view.</p>
<p>Ok so thats pretty much it. If you followed the examples word for word you after setting up your web application you should be able to visit <a href="http://localhost:8080/dynamiclists/processClassForm.page">http://localhost:8080/dynamiclists/processClassForm.page</a> and test your web app.</p>
<p>You can also <a href="http://eggsylife.co.uk/SpringDynamicListsExample.zip" target="_blank">download the example project here</a> within the project there is a docs folder that also includes a sample Tomcat context file for application deployment.</p>
<p>References: <a href="http://blog.richardadamdean.com/?page_id=119">http://blog.richardadamdean.com/?page_id=119</a></p>
<p>Any comments or questions are always welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/11/30/spring-forms-dynamic-lists-and-ajax/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Ajax Spring Forms with Annotations and jQuery</title>
		<link>http://eggsylife.co.uk/2009/11/12/ajax-spring-forms-with-annotations-and-jquery/</link>
		<comments>http://eggsylife.co.uk/2009/11/12/ajax-spring-forms-with-annotations-and-jquery/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 10:30:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ajax form]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring annotations]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=152</guid>
		<description><![CDATA[In one of my previous posts we documented how to implement Spring Annotations with a form. If you haven&#8217;t got a copy of the project from that post you can grab it here. Building on that example this guide shows how, using Spring and jQuery, you can Ajaxify your forms so that when submitted the [...]]]></description>
			<content:encoded><![CDATA[<div class="none"><div class="g-plusone" data-href="http://eggsylife.co.uk/2009/11/12/ajax-spring-forms-with-annotations-and-jquery/" size="medium" count="true"></div></div><p>In one of my previous posts we documented <a href="http://eggsylife.co.uk/2009/11/06/spring-annotations-and-forms/">how to implement Spring Annotations with a form</a>. If you haven&#8217;t got a copy of the project from that post you can <a href="http://eggsylife.co.uk/SpringAnnotationsExample.zip">grab it here.</a></p>
<p>Building on that example this guide shows how, using Spring and jQuery, you can Ajaxify your forms so that when submitted the user doesn&#8217;t have to be redirected to a new page</p>
<p><strong>jQuery and required plugins</strong></p>
<p>Create a new folder in the root of your project and call it &#8216;js&#8217;</p>
<p>Then grab a copy of <a href="http://docs.jquery.com/Downloading_jQuery">jQuery</a>. The minified version will be fine. Add the jQuery javascript file to your &#8216;js&#8217; folder.</p>
<p>Currently it is at version 1.3.2 so I have a file called jquery-1.3.2.min.js in my js folder</p>
<p>Next download a very useful plugin the <a href="http://www.malsup.com/jquery/form/">jQuery Form Plugin</a>. Also place the plugin in your js folder.</p>
<p><strong>Linking your JS</strong></p>
<p>Open the form.jsp file and add the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;/annotations/js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/annotations/js/jquery.form.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Here we are linking to the two jQuery javascript files we have just downloaded. Note I reference /annotations/ that is my application name yours may however be different.</p>
<p><strong>Convert the form to Ajax</strong></p>
<p>This step involves using the jQuery form plugin to make your form submit via Ajax. After including the scripts add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> formOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>target<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#nameFormResponse'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nameForm'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxForm</span><span style="color: #009900;">&#40;</span>formOptions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This assumes you are quite comfortable with jQuery but just to explain, in the above code we are saying that when the document is read fetch the form with the id of nameForm and convert it to  an ajaxForm (The ajaxForm function is built into the form plugin we download). We are also specifying some options for the ajaxForm method namely the target. A target is an jQuery selector that the Ajax Form plugin will automatically populate with the response from your submit</p>
<p>After your form go ahead and add in the div with the same id as the target, in the case above id=&#8221;nameFormResponse&#8221;.</p>
<p>The whole form.jsp should now look like so:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ taglib prefix=&quot;form&quot; uri=&quot;http://www.springframework.org/tags/form&quot; %&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot; src=&quot;/annotations/js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/annotations/js/jquery.form.js&quot;&gt;&lt;/script&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function() { 
		var formOptions = {target: '#nameFormResponse'};
		$('#nameForm').ajaxForm(formOptions);
	});
&lt;/script&gt;
&nbsp;
&nbsp;
&lt;form:form method=&quot;post&quot; name=&quot;nameForm&quot; id=&quot;nameForm&quot; commandName=&quot;nameCommand&quot;&gt;
	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;Name:&lt;/td&gt;
			&lt;td&gt;&lt;form:input path=&quot;name&quot; size=&quot;40&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&amp;nbsp;&lt;/td&gt;
			&lt;td&gt;&lt;input type=&quot;submit&quot; value=&quot;Send my name&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
&lt;/form:form&gt;
&nbsp;
&lt;div id=&quot;nameFormResponse&quot;&gt;
&lt;/div&gt;</pre></div></div>

<p>That should be it &#8211; so now if you visit <em>http://localhost:8080/annotations/processName.page</em> and submit the form you will see that the page doesn&#8217;t change and we render the response of the form submit into our nameFormResponse div element.</p>
<p><strong>You can <a href="/SpringAnnotationsAjax.zip">grab a copy of this project here</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/11/12/ajax-spring-forms-with-annotations-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

