<?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; Google Web Toolkit</title>
	<atom:link href="http://eggsylife.co.uk/category/gwt/feed/" rel="self" type="application/rss+xml" />
	<link>http://eggsylife.co.uk</link>
	<description>Eggsylife</description>
	<lastBuildDate>Thu, 22 Apr 2010 20:45:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GWT 2, JSONP and Javascript Overlays with JsonpRequestBuilder</title>
		<link>http://eggsylife.co.uk/2010/04/22/gwt-2-jsonp-and-javascript-overlays-with-jsonprequestbuilder/</link>
		<comments>http://eggsylife.co.uk/2010/04/22/gwt-2-jsonp-and-javascript-overlays-with-jsonprequestbuilder/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 12:24:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[cross site requests]]></category>
		<category><![CDATA[gwt 2.0]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[jsonprequestbuilder]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=249</guid>
		<description><![CDATA[In one of my earlier posts I discussed the topic of making cross site requests with Google Web toolkit.
Since that post Google have updated Web toolkit, currently version 2.0.3 and has now made it easier to make cross site requests through the use of their new JsonpRequestBuilder object and the Javascript object overlay types for [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my earlier posts I <a href="http://eggsylife.co.uk/2008/10/10/gwt-and-cross-site-jsonp-in-j2ee-container/">discussed the topic of making cross site requests</a> with <a href="http://eggsylife.co.uk/category/gwt/">Google Web toolkit</a>.</p>
<p>Since that post Google have updated Web toolkit, currently version 2.0.3 and has now made it easier to make cross site requests through the use of their new <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/jsonp/client/JsonpRequestBuilder.html" target="_blank">JsonpRequestBuilder</a> object and the Javascript object overlay types for result encapsulation.</p>
<p>This is a quick tutorial update on how to make use of the object overlay types. The application contacts the <a href="http://www.geonames.org/export/web-services.html" target="_blank">Geonames webservice</a>. For the example I shall use the &#8216;Placename lookup with postalcode (JSON)&#8217; function by making the following call:</p>
<p><a href="http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&#038;country=GB&#038;maxRows=4" target="_blank">http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&#038;country=GB&#038;maxRows=4</a></p>
<p>This returns location details for places matching the <i>M1</i> post code so central Manchester in the United Kingdom.</p>
<p>The results this request return are as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;postalcodes&quot;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;adminCode3&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;BN&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminName3&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Manchester District (B)&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminCode2&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;postalcode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;M1 1AD&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminCode1&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ENG&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;countryCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;GB&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;lng&quot;</span><span style="color: #339933;">:-</span><span style="color: #CC0000;">2.24521599415295</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;placeName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;City Centre Ward&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;lat&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">53.4838491117407</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminName1&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;England&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;adminCode3&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;BN&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminName3&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Manchester District (B)&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminCode2&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;postalcode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;M1 1AE&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminCode1&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ENG&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;countryCode&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;GB&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;lng&quot;</span><span style="color: #339933;">:-</span><span style="color: #CC0000;">2.23116928236428</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;placeName&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Ancoats and Clayton Ward&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;lat&quot;</span><span style="color: #339933;">:</span><span style="color: #CC0000;">53.4834816441844</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;adminName1&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;England&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you look at the previous JSON data it seems we have a list of &#8216;<em>postalcodes</em>&#8216; and each postal code has various fields such as adminName3, placeName etc.</p>
<p>Using GWT Javascript object overlays we can represent this structure. Within your GWT client directory create a new class called <strong>PostcodeEntry</strong> 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;">com.google.gwt.core.client.JavaScriptObject</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PostcodeEntry <span style="color: #000000; font-weight: bold;">extends</span> JavaScriptObject <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> PostcodeEntry<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #003399;">String</span> getAdminCode3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		return this.adminCode3;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> setNumberPlaceHolderId<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> adminCode3<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		this.adminCode3 = adminCode3;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #003399;">String</span> getAdminName3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		return this.adminName3;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> setAdminName3<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> adminName3<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		this.adminName3 = adminName3;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #003399;">String</span> getPostalcode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		return this.postalcode;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> setPostalcode<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> postalcode<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		this.postalcode = postalcode;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #003399;">String</span> getPlaceName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		return this.placeName;
	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> setPlaceName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> placeName<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
		this.placeName = placeName;
	}-*/</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Each PostcodeEntry represents one postalcode as you can see we have the functions for the various properties of a postalcode. Also note we extend the GWT <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/core/client/JavaScriptObject.html" target="_blank">JavascriptObject</a>. In the above example you&#8217;ll notice I haven&#8217;t implemented every property. This is by choice I have only implemented a few of the properties.</p>
<p>Now we need to build an object that maintains the collection of PostcodeEntry object. Essentially the object that represents the postalcodes array. Create a new Java object called &#8216;<strong>PostalCodes</strong>&#8216;. Add the following content:</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;">com.google.gwt.core.client.JavaScriptObject</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.core.client.JsArray</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PostalCodes <span style="color: #000000; font-weight: bold;">extends</span> JavaScriptObject <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> PostalCodes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">native</span> JsArray<span style="color: #339933;">&lt;</span>PostcodeEntry<span style="color: #339933;">&gt;</span> getPostalCodes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">/*-{
    	return this.postalcodes;
  	}-*/</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The object quite simply has one method called getPostalCodes which you&#8217;ll notice is a collection of PostcodeEntry objects and the native method simply called this.postalcodes which if you remember was the name of the array in the JSON response.</p>
<p>Those two objects wrap up the Geonames JSON response.</p>
<p>Finally we just need to write the code that invokes the service using the <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/jsonp/client/JsonpRequestBuilder.html" target="_blank">JsonpRequestBuilder</a> object.</p>
<p>Locate your GWT entry point and add the following code.</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;">com.google.gwt.core.client.EntryPoint</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.jsonp.client.JsonpRequestBuilder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.Window</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.AsyncCallback</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.HorizontalPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.Label</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.RootPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.VerticalPanel</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Entry point classes define &lt;code&gt;onModuleLoad()&lt;/code&gt;.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JsonpExample <span style="color: #000000; font-weight: bold;">implements</span> EntryPoint <span style="color: #009900;">&#123;</span>
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * This is the entry point method.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onModuleLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//</span>
	<span style="color: #666666; font-style: italic;">// http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&amp;country=GB&amp;maxRows=4</span>
	<span style="color: #666666; font-style: italic;">//</span>
	JsonpRequestBuilder jsonp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JsonpRequestBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&amp;country=GB&amp;maxRows=4&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	jsonp.<span style="color: #006633;">requestObject</span><span style="color: #009900;">&#40;</span>url, <span style="color: #000000; font-weight: bold;">new</span> AsyncCallback<span style="color: #339933;">&lt;</span>PostalCodes<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    @Override
	    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onFailure<span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> caught<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Failure:&quot;</span> <span style="color: #339933;">+</span> caught.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            @Override
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSuccess<span style="color: #009900;">&#40;</span>PostalCodes result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                VerticalPanel vp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VerticalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">getPostalCodes</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> count <span style="color: #339933;">&lt;</span> result.<span style="color: #006633;">getPostalCodes</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> count<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			PostcodeEntry entry <span style="color: #339933;">=</span> result.<span style="color: #006633;">getPostalCodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			HorizontalPanel hp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HorizontalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hp.<span style="color: #006633;">setSpacing</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hp.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>entry.<span style="color: #006633;">getPostalcode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hp.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Label</span><span style="color: #009900;">&#40;</span>entry.<span style="color: #006633;">getPlaceName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			vp.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>hp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		   <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#125;</span>
               RootPanel.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>vp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There are few important areas of this code to take note.</p>
<p>First of all note the use of the JsonpRequestBuilder object. We simply give this a Url which in this case is the Geoname service url. Those who are familiar with cross site requests will notice that the URL I specified doesn&#8217;t contain the &#8216;callback&#8217; parameter. The JsonpRequestBuilder automatically appends this to the end of the URL for us so we have &#038;callback=gwt_IOSucess appended to the request. It defaults the parameter name to &#8216;callback&#8217; but if the service requires a different parameter name you can change this by calling <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/jsonp/client/JsonpRequestBuilder.html#setCallbackParam%28java.lang.String%29" target="_blank">setCallbackParam</a>.</p>
<p>Next we simply call requestObject that takes an Async callback which is of our Postalcodes type. This clears up why we use object overlays.</p>
<p>Finally the onSuccess method takes in the Postalcodes as an argument and we are then free to pick away at the response and the various postalcode entries in the result.</p>
<p>I hope this has helped people to start making use of the new GWT JSONP functions and object overlays. </p>
<p>You can also <a href="http://eggsylife.co.uk/JsonpExample.zip">download the source code</a> for this example.</p>
<p>Please any comments welcome&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2010/04/22/gwt-2-jsonp-and-javascript-overlays-with-jsonprequestbuilder/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GWT 2.0 Declarative Interface Tutorial Project Download</title>
		<link>http://eggsylife.co.uk/2009/11/05/gwt-2-0-declarative-interface-tutorial-project-download/</link>
		<comments>http://eggsylife.co.uk/2009/11/05/gwt-2-0-declarative-interface-tutorial-project-download/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 09:40:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[declarative interfaces tutorial]]></category>
		<category><![CDATA[example project]]></category>
		<category><![CDATA[gwt 2.0]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=95</guid>
		<description><![CDATA[I have now made the project used in the GWT 2.0 tutorials available for download.
The project includes declarative interfaces and method binding. It also includes the original GWT RPC example code so the application acts exactly the same as the GWT created example
Project Download
]]></description>
			<content:encoded><![CDATA[<p>I have now made the project used in the <a href="http://eggsylife.co.uk/WebApplication.zip">GWT 2.0 tutorials available for download.</a></p>
<p>The project includes declarative interfaces and method binding. It also includes the original GWT RPC example code so the application acts exactly the same as the GWT created example</p>
<p><a href="http://eggsylife.co.uk/WebApplication.zip">Project Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/11/05/gwt-2-0-declarative-interface-tutorial-project-download/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>GWT 2.0 Declarative Interfaces Event Handler Binding</title>
		<link>http://eggsylife.co.uk/2009/11/04/gwt-2-0-declarative-interfaces-event-handler-binding/</link>
		<comments>http://eggsylife.co.uk/2009/11/04/gwt-2-0-declarative-interfaces-event-handler-binding/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 12:52:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[declarative interfaces tutorial]]></category>
		<category><![CDATA[gwt 2.0]]></category>
		<category><![CDATA[gwt 2.0 userguide]]></category>
		<category><![CDATA[gwt rc2]]></category>
		<category><![CDATA[method binding]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=90</guid>
		<description><![CDATA[Moving on from the previous tutorial on GWT 2.0 Declarative Interfaces version 2 of GWT also allows dynamic method binding.
This means that simply by adding a few Java annotations we can bind methods to interface objects. In the past we would have to add a new ClickHandler to our code and set the click handler [...]]]></description>
			<content:encoded><![CDATA[<p>Moving on from the previous tutorial on <a href="http://eggsylife.co.uk/2009/11/01/gwt-2-0-declarative-interfaces/">GWT 2.0 Declarative Interfaces</a> version 2 of GWT also allows dynamic method binding.</p>
<p>This means that simply by adding a few <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html">Java annotations</a> we can bind methods to interface objects. In the past we would have to add a new <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/event/dom/client/ClickHandler.html">ClickHandler</a> to our code and set the click handler in the widget. Now we can easily bind method.</p>
<p>Using the code we worked on last time within the WebApplication class we&#8217;re going to add a method binding to our sendButton go ahead and add the following method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> onSendButton<span style="color: #009900;">&#40;</span>ClickEvent event<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You clicked the sendButton'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The intention of this method is to display an typical <a href="http://www.w3schools.com/JS/js_popup.asp">Javascript alert</a> to the web page visitor saying &#8216;You clicked the sendButton&#8217;. (Basic I know)</p>
<p>Next we can add our binding annotations before the method declaration add the following annotation:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@UiHandler<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sendButton&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>So the complete method looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@UiHandler<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sendButton&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000066; font-weight: bold;">void</span> onSendButton<span style="color: #009900;">&#40;</span>ClickEvent event<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You clicked the sendButton'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And thats it! Now we have bound the onSendButton method to our sendButton. If you test the application you should be able to click the button and see the alert</p>
<p>That are a variety of method bindings possible such as KeyHandlers, for more information please see the <a href="http://code.google.com/p/google-web-toolkit/wiki/UiBinder">UiBinding Wiki</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/11/04/gwt-2-0-declarative-interfaces-event-handler-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT 2.0 Declarative Interfaces</title>
		<link>http://eggsylife.co.uk/2009/11/01/gwt-2-0-declarative-interfaces/</link>
		<comments>http://eggsylife.co.uk/2009/11/01/gwt-2-0-declarative-interfaces/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 20:25:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[declarative interfaces tutorial]]></category>
		<category><![CDATA[gwt 2.0]]></category>
		<category><![CDATA[gwt 2.0 userguide]]></category>
		<category><![CDATA[uiBinder]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=67</guid>
		<description><![CDATA[Ok so if you&#8217;ve followed the previous stage you&#8217;ll have a running web application that looks like the following:

This is the sample web application that GWT creates and it demonstrates some of the properties of GWT including Remote Procedure Calls (RPC). Clicking on the send button sends the name entered to the server and the [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so if you&#8217;ve followed the previous stage you&#8217;ll have a running web application that looks like the following:</p>
<p><a href="http://eggsylife.co.uk/wp-content/uploads/2009/11/gwt2screen1.JPG"><img src="http://eggsylife.co.uk/wp-content/uploads/2009/11/gwt2screen1-150x150.jpg" alt="GWT2Screen Full" title="GWT2Screen Full" width="150" height="150" class="aligncenter size-thumbnail wp-image-82" /></a></p>
<p>This is the sample web application that GWT creates and it demonstrates some of the properties of GWT including Remote Procedure Calls (RPC). Clicking on the send button sends the name entered to the server and the server responds.</p>
<p>We&#8217;ll convert this example to use Declarative User Interfaces.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2385645787721542";
/* ContentAdvert */
google_ad_slot = "6547963405";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h3>Editing the GWT Module defintion</h3>
<p>Your application will have associated with it a gwt.xml module defintion we need to edit this to include the Ui Binder utilities</p>
<p>It can be found under the src directory and in the folder com/webapplication folder.</p>
<p>Simply add the following line</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;inherits</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;com.google.gwt.uibinder.UiBinder&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<h3>Editing the application HTML</h3>
<p>Using Eclipse expand the war folder and you should have a HTML file which will be the same name as you had entered when creating the project. In my case WebApplication.html</p>
<p>We&#8217;ll strip out most of the code on the HTML page as its not needed and we can simplify things</p>
<p>Make your HTML the same as the following:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&nbsp;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
    &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;WebApplication.css&quot;&gt;
    &lt;title&gt;Web Application Starter Project&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;webapplication/webapplication.nocache.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
&nbsp;
    &lt;!-- OPTIONAL: include this if you want history support --&gt;
    &lt;iframe src=&quot;javascript:''&quot; id=&quot;__gwt_historyFrame&quot; tabIndex='-1' style=&quot;position:absolute;width:0;height:0;border:0&quot;&gt;&lt;/iframe&gt;
    &lt;!-- RECOMMENDED if your web app will not function without JavaScript enabled --&gt;
    &lt;noscript&gt;
      &lt;div style=&quot;width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif&quot;&gt;
        Your web browser must have JavaScript enabled
        in order for this application to display correctly.
      &lt;/div&gt;
    &lt;/noscript&gt;
&nbsp;
    &lt;h1&gt;Web Application Starter Project&lt;/h1&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>So that simplifies the HTML of the application we can now simplify the code of the main application.</p>
<h3>Editing the EntryPoint and binding Widgets</h3>
<p>Depending on your chosen names when creating the project the GWT plugin will have created a package similar to <strong>com.webapplication.client</strong>. Under this package you should have a couple of Interfaces (they&#8217;re for the RPC calls) and a class which is the main application point. Using my package name as the example the class is called WebApplication.java</p>
<p>This class is the main entry point for the application. You can think of this as similar to the main method for a Java native application</p>
<p>There should be a method called</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">onModuleLoad</pre></div></div>

<p> This is the Main method. </p>
<p>In this method right at the start we declare two interface objects &#8211; sendButton and nameField. We&#8217;re going to use declarative interfaces for these buttons so they can be removed from the module load. Remove the folllowing lines:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Button</span> sendButton <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Send&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> TextBox nameField <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextBox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
nameField.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GWT User&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We can now move those two objects and make them class variables. You&#8217;ll notice the declaration of the GreetingService. Under this add the following lines</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@UiField <span style="color: #003399;">Button</span> sendButton<span style="color: #339933;">;</span>
@UiField TextBox nameField<span style="color: #339933;">;</span></pre></div></div>

<p>This will make sure your code compiles again. Notice the use of a new Java annotation @UiField. This is a key feature to UiBinding and GWT declarative interfaces.</p>
<p>Also notice we do not declare the variables as private to the class, they need to be visible so protected at a minimum</p>
<p>Any UI object that your declare can be bound in this way. When we create the declarative interface file for the application you will see where the UI objects are defined and how the bounding happens</p>
<p>Next we need to bind the template file to the class. Just under your class defintion add the following lines:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@UiTemplate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WebApplication.ui.xml&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">interface</span> Binder <span style="color: #000000; font-weight: bold;">extends</span> UiBinder<span style="color: #339933;">&lt;</span>VerticalPanel, WebApplication<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
<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> Binder binder <span style="color: #339933;">=</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>Binder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the above code we declare the template file we are going to use (This can be any name you like) and we bind a widget using the UiBinder. In my case I&#8217;m using a simple VerticalPanel for my layout</p>
<p>Now we need to get this VerticalPanel and add it to our layout</p>
<p>Within your onModuleLoad method add the following code as the first line of the method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">VerticalPanel vp <span style="color: #339933;">=</span> binder.<span style="color: #006633;">createAndBindUi</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Below that you will have a lot of code that declares styles, click handlers, a dialog box and the adding of widgets to in layout. For now we&#8217;ll remove most of this code. We&#8217;ll reintroduce it when we need it</p>
<p>We&#8217;ll just add a line that adds our declared panel to the layout.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">RootPanel.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>vp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Your onModuleLoad method should now be simpler and look like the following:</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;">/**
 * This is the entry point method.
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onModuleLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
     VerticalPanel vp <span style="color: #339933;">=</span> binder.<span style="color: #006633;">createAndBindUi</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// We can add style names to widgets</span>
     sendButton.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sendButton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">// Focus the cursor on the name field when the app loads</span>
     nameField.<span style="color: #006633;">setFocus</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     nameField.<span style="color: #006633;">selectAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     RootPanel.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>vp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The whole class should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.WebApplication.client</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.core.client.EntryPoint</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.core.client.GWT</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.uibinder.client.UiBinder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.uibinder.client.UiField</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.uibinder.client.UiTemplate</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.RootPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.TextBox</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.VerticalPanel</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Entry point classes define &lt;code&gt;onModuleLoad()&lt;/code&gt;.
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WebApplication <span style="color: #000000; font-weight: bold;">implements</span> EntryPoint
<span style="color: #009900;">&#123;</span>
	@UiTemplate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WebApplication.ui.xml&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">interface</span> Binder <span style="color: #000000; font-weight: bold;">extends</span> UiBinder<span style="color: #339933;">&lt;</span>VerticalPanel, WebApplication<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span>
	<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> Binder binder <span style="color: #339933;">=</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>Binder.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */</span>
	<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> SERVER_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;An error occurred while &quot;</span>
						 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;attempting to contact the server. Please check your network &quot;</span>
						 <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;connection and try again.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Create a remote service proxy to talk to the server-side Greeting
	 * service.
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> GreetingServiceAsync greetingService <span style="color: #339933;">=</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>GreetingService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	@UiField <span style="color: #003399;">Button</span> sendButton<span style="color: #339933;">;</span>
	@UiField TextBox nameField<span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * This is the entry point method.
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onModuleLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		VerticalPanel vp <span style="color: #339933;">=</span> binder.<span style="color: #006633;">createAndBindUi</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// We can add style names to widgets</span>
		sendButton.<span style="color: #006633;">addStyleName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sendButton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Focus the cursor on the name field when the app loads</span>
		nameField.<span style="color: #006633;">setFocus</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		nameField.<span style="color: #006633;">selectAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		RootPanel.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>vp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For now thats it on the Java side</p>
<h3>Declaring the interface</h3>
<p>Remember we added a line that used the @UiTemplate annotation and we declared a ui.xml template. (In my example WebApplication.ui.xml). We can now go ahead and create this file</p>
<p>In the same location as your Entry Point (WebApplication class) add a new file of the same name of your template. In my case I created a file called WebApplication.ui.xml</p>
<p>Add the following contents to your ui.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;ui:UiBinder</span> <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">'urn:ui:com.google.gwt.uibinder'</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:g</span>=<span style="color: #ff0000;">'urn:import:com.google.gwt.user.client.ui'</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:webapplication</span>=<span style="color: #ff0000;">'urn:import:com.WebApplication.client'</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;/ui:UiBinder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Notice we declare add the uiBinder tags with XML namespaces. The final namespace must match your client package name and application. If you are unsure of your application name you can check this in the GWT module definition file.(WebApplication.gwt.xml)</p>
<p>Within those tags we can add the declaration of our VerticalPanel</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;g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ok now we can add in the contents of the VerticalPanel which include our sendButton and nameField that will be bound</p>
<p>Add the contents shown below to your VerticalPanel definition:</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;g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Please enter your name:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:HorizontalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:TextBox</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">'GWT User'</span> <span style="color: #000066;">ui:field</span>=<span style="color: #ff0000;">'nameField'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:Button</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">'Send'</span> <span style="color: #000066;">ui:field</span>=<span style="color: #ff0000;">'sendButton'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g:HorizontalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The whole file should like similar to the following:</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;ui:UiBinder</span> <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">'urn:ui:com.google.gwt.uibinder'</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:g</span>=<span style="color: #ff0000;">'urn:import:com.google.gwt.user.client.ui'</span></span>
<span style="color: #009900;">             <span style="color: #000066;">xmlns:webapplication</span>=<span style="color: #ff0000;">'urn:import:com.WebApplication.client'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:Label</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">&quot;Please enter your name:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:HorizontalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:TextBox</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">'GWT User'</span> <span style="color: #000066;">ui:field</span>=<span style="color: #ff0000;">'nameField'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	 		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g:Button</span> <span style="color: #000066;">text</span>=<span style="color: #ff0000;">'Send'</span> <span style="color: #000066;">ui:field</span>=<span style="color: #ff0000;">'sendButton'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	 	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g:HorizontalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g:VerticalPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ui:UiBinder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>At this stage you should be able to run the application</p>
<p>Coming next method binding&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/11/01/gwt-2-0-declarative-interfaces/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>GWT 2.0 &#8211; First look and Guide</title>
		<link>http://eggsylife.co.uk/2009/10/28/gwt-2-0-first-look-and-guide/</link>
		<comments>http://eggsylife.co.uk/2009/10/28/gwt-2-0-first-look-and-guide/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 12:53:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[gwt 2.0]]></category>
		<category><![CDATA[gwt rc2]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=48</guid>
		<description><![CDATA[Today I have been testing setting up a new 2.0 Google Web Toolkit.
GWT 2.0 is currently on Milestone release so I thought I&#8217;d give it a try. I especially want to try out the GWT declarative UI features
I&#8217;ll go through the steps I have made to start the project. (I&#8217;m assuming you are using Eclipse [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have been testing setting up a new 2.0 Google Web Toolkit.</p>
<p><a href="http://code.google.com/p/google-web-toolkit/downloads/list?can=1&amp;q=2.0+Milestone+2" target="_blank">GWT 2.0 is currently on Milestone release</a> so I thought I&#8217;d give it a try. I especially want to try out the GWT declarative UI features</p>
<p>I&#8217;ll go through the steps I have made to start the project. (I&#8217;m assuming you are using Eclipse as your IDE)</p>
<h4>Step 1</h4>
<p>If you haven&#8217;t already download and install the <a href="http://code.google.com/appengine/docs/java/tools/eclipse.html" target="_blank">GWT and GAE (Google App Engine) plugins for Eclipse</a>.</p>
<h4>Step 2</h4>
<p>Download the <a href="http://code.google.com/p/google-web-toolkit/downloads/list?can=1&amp;q=2.0+Milestone+2" target="_blank">GWT 2.0 latest release candidate</a></p>
<h4>Step 3</h4>
<p>Add the new GWT 2.0 SDK to your IDE.</p>
<p><a href="http://eggsylife.co.uk/wp-content/uploads/2009/10/build_path_gwt.jpg"><img src="http://eggsylife.co.uk/wp-content/uploads/2009/10/build_path_gwt-150x150.jpg" alt="Build Paths" title="Build Paths" width="150" height="150" class="aligncenter size-thumbnail wp-image-52" /></a></p>
<p>To do so go to your Eclipse Settings/Preferences window and choose Google from the menu on the left hand side.</p>
<p>You&#8217;ll see different versions of GWT listed. Click the &#8216;Add&#8217; button to add the 2.0 SDK</p>
<p>From here you can browse and choose the GWT 2.0 SDK folder and enter GWT 2.0 in the name field</p>
<p>Once you have done so click OK</p>
<h4>Step 4</h4>
<p>Create a new Web Application Project</p>
<p>Click File>New>Web Application Project&#8230;</p>
<p>After populating your Project and Package name under Google SDK&#8217;s &#8211; Google Web Toolkit choose &#8216;Use specific SDK&#8217; and choose your GWT 2.0 from the drop down list. You can leave the Google App Engine version as it is. Click OK to create your project.</p>
<h4>Step 5</h4>
<p>Running the application</p>
<p>In Eclipse make sure you project is selected and choose &#8216;Run&#8217; from the menu</p>
<p>Click on &#8216;Open Run dialog&#8230;&#8217;</p>
<p>Down the left side you will see &#8216;Web Application&#8217; select that and click &#8216;Run&#8217;</p>
<p>You&#8217;ll then get an error similar to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Using a browser with the GWT Development Plugin<span style="color: #339933;">,</span> please browse to
the following URL<span style="color: #339933;">:</span>
  http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:8080/WebApplication.html?gwt.hosted=192.168.1.10:9997</span></pre></div></div>

<p>If you then browse to the URL it gives you will see a page telling you that you need to download and install a plugin for your browser</p>
<p>Download and install the plugin for your chosen browser</p>
<p>Once you have done so &#8211; close and quit the browser</p>
<p>Also on Eclipse make sure and stop the current running &#8216;Web Application&#8217;.</p>
<p>Then restart &#8216;Web Application&#8217; and when it gives you the same error navigate your browser to the URL given and this time you should see the GWT application correctly displayed <img src='http://eggsylife.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://eggsylife.co.uk/2009/11/01/gwt-2-0-declarative-interfaces/">Coming next &#8211; GWT 2.0 Declarative Interfaces&#8230;.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2009/10/28/gwt-2-0-first-look-and-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate, Spring and GWT for GWT 1.5</title>
		<link>http://eggsylife.co.uk/2008/11/26/hibernate-spring-and-gwt-for-gwt-1-5/</link>
		<comments>http://eggsylife.co.uk/2008/11/26/hibernate-spring-and-gwt-for-gwt-1-5/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 09:58:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[gwt 1.5]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=36</guid>
		<description><![CDATA[A few people have now let me know (quite rightly) that the Hibernate, Spring and GWT tutorial is now out of date after the release of GWT 1.5
I believe the application should still work but&#8230;.
As a result here is a summary of the changes you need to make to make the application to make it [...]]]></description>
			<content:encoded><![CDATA[<p>A few people have now let me know (quite rightly) that the Hibernate, Spring and GWT tutorial is now out of date after the release of GWT 1.5</p>
<p>I believe the application should still work but&#8230;.<br />
As a result here is a summary of the changes you need to make to make the application to make it 1.5 compatible.</p>
<p><span style="font-weight:bold;">JAR Files</span></p>
<p>Firstly update the GWT jar files within the WEB-INF/lib folder. Make sure you update the gwt-servlet jar as well this MUST be the GWT 1.5 gwt-servlet.jar!</p>
<p><span style="font-weight:bold;">Compile, Launch and Shell Scripts</span></p>
<p>The compile launch and shell scripts should all point at your new GWT 1.5 location</p>
<p><span style="font-weight:bold;">@gwt.typeArgs Annotations</span></p>
<p>Although this only causes warnings you should remove all the @gwt.typeArgs annotations completely from your project. With GWT 1.5 you can use strongly typed sets such List&lt;Object&gt;</p>
<p><span style="font-weight:bold;">@RemoteServiceRelativePath and RPC</span></p>
<p>GWT 1.5 has made it easier to call and define RPC services. In my example the TeacherService should now be defined as:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client.rpc</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.dto.PupilDTO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.RemoteService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.RemoteServiceRelativePath</span><span style="color: #339933;">;</span>
&nbsp;
@RemoteServiceRelativePath<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;teachers&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TeacherService <span style="color: #000000; font-weight: bold;">extends</span> RemoteService
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>PupilDTO<span style="color: #339933;">&gt;</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice RemoteServiceRelativePath defintion that is our path.</p>
<p>You can then call the service much simpler:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">TeacherServiceAsync teacherService <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TeacherServiceAsync<span style="color: #009900;">&#41;</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>TeacherService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
teacherService.<span style="color: #006633;">getPupils</span><span style="color: #009900;">&#40;</span>teacherId, <span style="color: #000000; font-weight: bold;">new</span> AsyncCallback<span style="color: #339933;">&lt;</span>List<span style="color: #339933;">&lt;</span>PupilDTO<span style="color: #339933;">&gt;&gt;</span><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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onFailure<span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> caught<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</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> onSuccess<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>PupilDTO<span style="color: #339933;">&gt;</span> result<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span> 
        pupils <span style="color: #339933;">=</span> result<span style="color: #339933;">;</span>
        notifyObservers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I have also updated the project and this can be <a href="http://www.filefactory.com/file/9771e7/n/TheProject_zip">downloaded as a zip file</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2008/11/26/hibernate-spring-and-gwt-for-gwt-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT and Cross Site JSONP in J2EE Container</title>
		<link>http://eggsylife.co.uk/2008/10/10/gwt-and-cross-site-jsonp-in-j2ee-container/</link>
		<comments>http://eggsylife.co.uk/2008/10/10/gwt-and-cross-site-jsonp-in-j2ee-container/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 09:56:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=29</guid>
		<description><![CDATA[Before starting this tutorial entry its worth mentioning a few people who have helped my along the one. Firstly a member of the GWT Group named AdamT who helped clear up a lot of things when implementing Cross Site JSONP calls. We had a discussion on the GWT group:
Group Link
Secondly Dan Morill of Google who [...]]]></description>
			<content:encoded><![CDATA[<p>Before starting this tutorial entry its worth mentioning a few people who have helped my along the one. Firstly a member of the GWT Group named AdamT who helped clear up a lot of things when implementing Cross Site JSONP calls. We had a discussion on the GWT group:</p>
<p><a href="http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/dadc417fd0adc58a" target="_blank">Group Link</a></p>
<p>Secondly Dan Morill of Google who has wrote a very descriptive article on how to achieve this and much of this tutorial is based around his article.</p>
<p><a href="http://code.google.com/support/bin/answer.py?answer=65632&#038;topic=11368" target="_blank">Dans Article</a></p>
<p>And finally my boss Chris who after I implemented the code finally caused the light bulb that had been dwindling (due to high energy costs and the <span style="font-style:italic;">credit crunch</span> )to flash on!</p>
<p>Ok on with the tutorial&#8230;.</p>
<p>This tutorial aims to describe how to implement Cross Site Scripting using JSONP and GWT. This problem fell into my hands because I needed to make a GWT widget that could be hosted on anybodies web site that could communicate with our web server.</p>
<p>You can solve this in one of two ways &#8211; firstly host the widget on your server and then for the pages simply iFrame the page to load the content in on different websites. Thus getting over the XSS problem. This wasn&#8217;t an option for me, the &#8216;client&#8217; in this case didn&#8217;t particularly want an iFrame and I cant say I blame them.</p>
<p>So the second way you do this is JSONP and some clever GWT native Javascript methods. I&#8217;ll take it as given that people understand JSON but if they don&#8217;t there are quite a few useful links from Dans article. Also I&#8217;ll assume that people are used to tuning their web.xml file so that URL&#8217;s are mapped to Servlets correctly.</p>
<p>Right now the first part of sample code. This is my sample servlet that produces some basic JSON javascript</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> MySampleServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */</span>
     @Override
     <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span>
     <span style="color: #009900;">&#123;</span>
         doPost<span style="color: #009900;">&#40;</span>req, resp<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 javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */</span>
      @Override
      <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doPost<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span>    
      <span style="color: #009900;">&#123;</span>
&nbsp;
          <span style="color: #003399;">String</span> asyncCallback <span style="color: #339933;">=</span> req.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;callback&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003399;">String</span> output <span style="color: #339933;">=</span> asyncCallback<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;([{color: <span style="color: #000099; font-weight: bold;">\&quot;</span>red<span style="color: #000099; font-weight: bold;">\&quot;</span>,value: <span style="color: #000099; font-weight: bold;">\&quot;</span>#f00<span style="color: #000099; font-weight: bold;">\&quot;</span>}])&quot;</span><span style="color: #339933;">;</span>
&nbsp;
          resp.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          resp.<span style="color: #006633;">addHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Pragma&quot;</span>, <span style="color: #0000ff;">&quot;no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          resp.<span style="color: #006633;">setStatus</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #003399;">PrintWriter</span> out <span style="color: #339933;">=</span> resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          out.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You just then need to map that servlet in your web.xml. For the user of this example mine is mapped to testServlet.</p>
<p>What that outputs is something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">&nbsp;
_gwt__callback0([{
                    color: &quot;red\&quot;,
                    value: &quot;#f00&quot;
               }]);</pre></div></div>

<p>The crucial part of this output is the _gwt__callback0 this identifies the Javascript callback function and I&#8217;ll explain where that is used.</p>
<p>Now back to the client side code, this is taken a lot from Dan&#8217;s article and isn&#8217;t really covering any new ground that he hasn&#8217;t already covered. This code makes the XSS call when a button is clicked. </p>
<p>The code is below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Used to identify the particular callback</span>
 <span style="color: #000000; font-weight: bold;">protected</span> HashMap<span style="color: #339933;">&lt;</span>Integer, Object<span style="color: #339933;">&gt;</span> callbacks <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>Integer, Object<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">protected</span> HashMap<span style="color: #339933;">&lt;</span>String, Element<span style="color: #339933;">&gt;</span> scriptTags <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, Element<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">int</span> curIndex <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> someMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    but.<span style="color: #006633;">addClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ClickListener<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>Widget arg0<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">String</span> serverURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://localhost:8080/myApp/testServlet?callback=&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">String</span> callbackName <span style="color: #339933;">=</span> reserveCallback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            setup<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, callbackName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            addScript<span style="color: #009900;">&#40;</span>callbackName, serverURL <span style="color: #339933;">+</span> callbackName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</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;">public</span> <span style="color: #003399;">String</span> reserveCallback<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;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> 
     <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>callbacks.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>curIndex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
      <span style="color: #009900;">&#123;</span>
       callbacks.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>curIndex<span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span><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;__gwt_callback&quot;</span> <span style="color: #339933;">+</span> curIndex<span style="color: #339933;">++;</span>
      <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * &lt;p&gt;Adds the JSONP script to our widget so we can make XSS requests baby&lt;/p&gt;
  * 
  * @param uniqueId The unique id of the call
  * @param url The URL of our Request
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000066; font-weight: bold;">void</span> addScript<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> id, <span style="color: #003399;">String</span> url<span style="color: #009900;">&#41;</span> 
 <span style="color: #666666; font-style: italic;">/*-{
     var elem = document.createElement(&quot;script&quot;);
     elem.setAttribute(&quot;language&quot;, &quot;JavaScript&quot;);
     elem.setAttribute(&quot;src&quot;, url);
     elem.setAttribute(&quot;id&quot;, id);
     document.getElementsByTagName(&quot;body&quot;)[0].appendChild(elem);
 }-*/</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> handle<span style="color: #009900;">&#40;</span>JavaScriptObject jso<span style="color: #009900;">&#41;</span> 
 <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> jso <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Window</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Woohoo JSO is not null it bloody worked&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;
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * 
  * &lt;p&gt;Sets up our Javascript cross site JSON call&lt;/p&gt;
  * 
  * @param model Handles our Cross Site JSON call
  * @param callback
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">native</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span>MyClass myClass, <span style="color: #003399;">String</span> callback<span style="color: #009900;">&#41;</span> 
 <span style="color: #666666; font-style: italic;">/*-{
      window[callback] = function(someData) 
      {
         myClass.@com.myCompany.MyClass::handle(Lcom/google/gwt/core/client/JavaScriptObject;)(someData);
      }
   }-*/</span><span style="color: #339933;">;</span></pre></div></div>

<p>Right now this needs describing as the syntax is a bit confusing. I&#8217;ll go through the onClick method and what it does bit by bit. First the server URL this is obvious and can be any server URL as you would expect. I simply use my app name (in this example myApp) and the servlet mapping as we mentioned earlier to be testServlet. One final thing on the URL is the callback parameter this is very important. If you look at our servlet we extract that and put it in our JSON output. </p>
<p>What the parameter does is basically allow the code to idenitify which method to call on the way back. The callback.</p>
<p>Next we set up the callback name nothing to exciting there it basically sets up a callback name based upon the number of calls &#8211; first one being _gwt_callback0, second _gwt__callback1 etc etc. We add this to a callbacks hash map for reference later if required.</p>
<p>The next very important method is setup(). This sets up the Javascript function that will be called on the callback and assigns it to the window object. We assign the function handle to the callback name ( initially __gwt_callback0 ) and the function it will call is the <span style="font-style:italic;">handle</span> method in that class.</p>
<p>The final method is the addScript method this basically does what it says and adds some &lt;script&gt; tags to our page. </p>
<p>Now because those tags get executed the browser sees that it needs to fetch some content from a server and it goes off and fetches that content. Thats a key point that the browser realises it must go off and make the call. Its basically like any web developer would do when they include script say in their head file the page/browser knows that it must go off and fetch that script so it does. In our case it goes off and fetches the script from our Java Servlet.</p>
<p>Ok the final part of the understanding is how the system knows what to do when coming back from the server. If we take a look at the <span style="font-style:italic;">setup</span> method you can see that we assigned the window[callback] to a function the function actually calls our handle method. </p>
<p>Now that callback would have been something like __gwt_callback0 with the number incrementing for every callback. So when we send over our JSON content, as described above, it invokes the function matching the name __gwt_callback0 and that actually invokes our handle method. Thats why the function name is so important.</p>
<p>(At this stage its worth pointing out that I&#8217;m making a big thing about the function name because that was the key part I missed in my understanding and AdamT cleared that up so you may have already got that <img src='http://eggsylife.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<p>Thats pretty much it. You can then do what you like with the JavascriptObject that is passed back into the <span style="font-style:italic;">handle</span> method. Dans article has a brief example of that.</p>
<p>Hope this all makes sense to people and will help describe JSONP and GWT somewhat. If people have questions please post as a comment so that everyone can see useful answers.</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2008/10/10/gwt-and-cross-site-jsonp-in-j2ee-container/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hibernate, Spring, Google Web Toolkit &#8211; Part Four</title>
		<link>http://eggsylife.co.uk/2008/09/05/hibernate-spring-google-web-toolkit-part-four/</link>
		<comments>http://eggsylife.co.uk/2008/09/05/hibernate-spring-google-web-toolkit-part-four/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 09:55:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[gwt tomcat setup]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring hibernate]]></category>
		<category><![CDATA[tomcat configuration]]></category>
		<category><![CDATA[web.xml]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=26</guid>
		<description><![CDATA[A few people have now requested the final step in the tutorial &#8211; making the application a true web app and how to setup the web.xml etc.
So thought it time to pull my finger out of my &#8230; and get it done.
This tutorial is based upon the previous tutorials in this work and is performed [...]]]></description>
			<content:encoded><![CDATA[<p>A few people have now requested the final step in the tutorial &#8211; making the application a true web app and how to setup the web.xml etc.</p>
<p>So thought it time to pull my finger out of my &#8230; and get it done.</p>
<p>This tutorial is based upon the previous tutorials in this work and is performed using Tomcat version 5.5. I think other tomcat versions should matter but dont quote me on that.</p>
<p>Firstly my sample context is as follows:</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;Context</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/theproject&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;/Users/james/Documents/workspace/TheProject&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">workDir</span>=<span style="color: #ff0000;">&quot;/Users/james/Documents/workspace/TheProjectWorkDir&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">crossContext</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Logger</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.logger.FileLogger&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;localhost_theproject_log.&quot;</span> <span style="color: #000066;">suffix</span>=<span style="color: #ff0000;">&quot;.txt&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">timestamp</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Thats stuff most should be comfortable with. On my setup I place my context file in CATALINA_HOME/conf/Catalina/localhost/</p>
<p>The next step is to compile up our GWT it Javascript.</p>
<p>Run your GWT application in hosted mode. </p>
<p>Then when ready click &#8216;Compile&#8217; on the GWT hosted mode browser. If you have the same launch/compile/shell scripts as the ones I defined in Part Two of the tutorial then you should get a new folder within your project titled <span style="font-weight:bold;"><span style="font-style:italic;">&#8216;www&#8217;</span></span>.</p>
<p>The next step is to make your web.xml and put it in the location /WEB-INF/web.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;?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>
&nbsp;
<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</span>
<span style="color: #009900;">   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;
&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>The Project<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;
    <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>theproject<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>theproject<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;
    <span style="color: #808080; font-style: italic;">&lt;!-- GWT Servlets   --&gt;</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>
        <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>teachers<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>com.company.server.gwt.TeacherServiceImpl<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;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
&nbsp;
&nbsp;
&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>teachers<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>/www/com.company.MyApplication/teachers<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;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webAppRootKey<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>theproject.root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-param<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;session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>45<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-timeout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- The Usual Welcome File List --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<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>A few important points in the web.xml are firtly notice the spring elements and I&#8217;m mapping anything with .page to go through my Spring controller.</p>
<p>Then also notice the GWT mappings &#8211; we&#8217;re using the url of teachers as defined in our RPC&#8217;s and pointing this at that www folder we made!! Easy so far!</p>
<p>Next we need to make the Spring servlet that handles the Spring controllers for sending back to the user a view. The name of the file is very important mine is called theproject-servlet.xml because this is the name used in my web.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;?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>
&nbsp;
<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:aop</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/aop&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:tx</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/tx&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">       http://www.springframework.org/schema/beans classpath:spring-beans-2.0.xsd</span>
<span style="color: #009900;">       http://www.springframework.org/schema/tx classpath:spring-tx-2.0.xsd</span>
<span style="color: #009900;">       http://www.springframework.org/schema/aop classpath:spring-aop-2.0.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;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: #808080; font-style: italic;">&lt;!-- no 'id' required, HandlerMapping beans are automatically detected by the DispatcherServlet --&gt;</span>
    <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;handlerMapping&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&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;mappings&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>
                 /**/help.page=simpleViewController
                 /home.page=homepageController                
            <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>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- List of controllers for the application --&gt;</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;simpleViewController&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.web.servlet.mvc.UrlFilenameViewController&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>
&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;homepageController&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.company.server.web.controlle.HomepageController&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;successView&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;home.tile&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;exceptionView&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;exception.tile&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>
&nbsp;
&nbsp;
 <span style="color: #808080; font-style: italic;">&lt;!-- Convention based ViewResolver for Tiles2 --&gt;</span>
 <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>
&nbsp;
<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>A few more important parts here &#8211; firstly the definition of a tiles file. Those familar with tiles should understand this. This is where we shall define all our pages. Secondly you can see our mappings &#8211; in this case home.page. They are handled by controllers. Notice the controller homepageController we&#8217;ll go ahead and define that class now:</p>
<p>Firstly in good Object oriented design we can make an abstract controller that all our controllers can extends for ease.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.server.web.controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.mvc.BaseCommandController</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> ParameterisedViewCommandController <span style="color: #000000; font-weight: bold;">extends</span> BaseCommandController
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> successView <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> exceptionView <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * @return the successView
  */</span>
 <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> getSuccessView <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> successView<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * @param successView the successView to set
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setSuccessView <span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> successView <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;">successView</span> <span style="color: #339933;">=</span> successView<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * @return the exceptionView
  */</span>
 <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> getExceptionView <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> exceptionView<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * @param exceptionView the exceptionView to set
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setExceptionView <span style="color: #009900;">&#40;</span> <span style="color: #003399;">String</span> exceptionView <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;">exceptionView</span> <span style="color: #339933;">=</span> exceptionView<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice the basic strings exception and success view that we defined in our servlet.xml file.</p>
<p>Next just the basic implementation of our defined HomepageController.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.server.web.controller</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.web.servlet.ModelAndView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HomepageController <span style="color: #000000; font-weight: bold;">extends</span> ParameterisedViewCommandController
<span style="color: #009900;">&#123;</span>
&nbsp;
 @Override
 <span style="color: #000000; font-weight: bold;">protected</span> ModelAndView handleRequestInternal<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ModelAndView<span style="color: #009900;">&#40;</span>getSuccessView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case we just return a new view of the success view but you can obviously return various views. Also those familiar with struts actions the classes above are basically those.</p>
<p>Now go ahead and make the tiles files defined in the servlet. Create a file as specified in location /WEB-INF/tiles-def/templates.xml and in here we can define our templates. Mine if below:</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;home.tile&quot;</span> <span style="color: #000066;">template</span>=<span style="color: #ff0000;">&quot;/pages/home.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;title&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;The Project&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;gwtjs&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/theproject/www/com.company.MyApplication/com.company.MyApplication.nocache.js&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>The tile definition probably needs some explaing. Firstly I&#8217;m using JSTL to do my various important inserts such as the title of the page and the insert of my GWT compiled up javascript. Again still referencing that www folder and our javascript.</p>
<p>Right the final step is to make that page so make a folder in the root of your project called pages and make a file called home.jsp.</p>
<p>My page is below:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ taglib uri=&quot;http://tiles.apache.org/tags-tiles&quot; prefix=&quot;tiles&quot; %&gt;
&nbsp;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&nbsp;
 &lt;head&gt;
  &lt;title&gt;&lt;tiles:getAsString name=&quot;title&quot; /&gt;&lt;/title&gt;
&nbsp;
  &lt;!-- Include the GWT Javascript --&gt;
  &lt;script language='javascript' src='&lt;tiles:getAsString name=&quot;gwtjs&quot; /&gt;'&gt;&lt;/script&gt;
 &lt;/head&gt;
&nbsp;
&nbsp;
 &lt;body&gt;
&nbsp;
  &lt;h1&gt;MyApplication&lt;/h1&gt;
&nbsp;
  &lt;p&gt;
   Example GWT application calling RPC calls
  &lt;/p&gt;
&nbsp;
  &lt;div id=&quot;database&quot;&gt;&lt;/div&gt;
&nbsp;
 &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>The important areas of the page are firstly the tiles inserts &#8211; where we insert of GWT javascript and also the content of the page between the body tags. The HTML is basically exactly the same as the hosted page. Our application looks for a &#8220;database&#8221; div to replace and such this element needs to be on the page!!</p>
<p>That should wrap everything up now! Also as I have migrated across to the latest versions of struts/spring/tiles etc you can <a href="http://www.fileshack.us/get_file.php?id=863543&#038;file=lib.zip">download a copy of my lib directory</a> so that the above tutorial should work.</p>
<p>Any questions please post a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2008/09/05/hibernate-spring-google-web-toolkit-part-four/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT SuggestBox backed by DTO Model</title>
		<link>http://eggsylife.co.uk/2008/08/25/gwt-suggestbox-backed-by-dto-model/</link>
		<comments>http://eggsylife.co.uk/2008/08/25/gwt-suggestbox-backed-by-dto-model/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 09:53:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[DTO SuggestBox tutorial]]></category>
		<category><![CDATA[DTO suggestoracle]]></category>
		<category><![CDATA[gwt suggestbox]]></category>
		<category><![CDATA[suggestbox]]></category>
		<category><![CDATA[suggestbox and DTO]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=24</guid>
		<description><![CDATA[In this post I am writing a tutorial on how to use the Google Web Toolkit SuggestBox when you want it to provide Data Transfer Objects (DTO&#8217;s) suggestions.
According to GWT&#8217;s official docs you can Associate DTO objects with SuggestBox suggestions but I struggled to find any guiding tutorials on how to achieve this.
Having said this [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I am writing a tutorial on how to use the Google Web Toolkit SuggestBox when you want it to provide Data Transfer Objects (DTO&#8217;s) suggestions.</p>
<p>According to GWT&#8217;s official docs you can <a href="http://google-web-toolkit-doc-1-5.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/SuggestOracle.Suggestion.html" target="_blank">Associate DTO objects with SuggestBox suggestions</a> but I struggled to find any guiding tutorials on how to achieve this.</p>
<p>Having said this I have to give credit to Lombardi who went someway to helping me to work out how to do this. Good explanations are posted on their <a href="http://development.lombardi.com/?p=45" target="_blank">blog.</a></p>
<p>First of all lets make a simple Data Transfer Object</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.IsSerializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonDTO <span style="color: #000000; font-weight: bold;">implements</span> IsSerializable
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the firstname
     */</span>
     <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>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param firstname the firstname to set
     */</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: #008000; font-style: italic; font-weight: bold;">/**
      * @return the lastname
      */</span>
      <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>
&nbsp;
     <span style="color: #008000; font-style: italic; font-weight: bold;">/**
      * @param lastname the lastname to set
      */</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>
&nbsp;
     <span style="color: #008000; font-style: italic; font-weight: bold;">/**
      * @return the id
      */</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<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> id<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #008000; font-style: italic; font-weight: bold;">/**
      * @param id the id to set
      */</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setId<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<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;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Thats the DTO object I&#8217;ll use throughout the tutorial.</p>
<p>Now we can make our Suggestion object as 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;">com.google.gwt.user.client.ui.MultiWordSuggestOracle.MultiWordSuggestion</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author James Heggs - jheggs@axonbirch.com
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonMultiWordSuggestion <span style="color: #000000; font-weight: bold;">extends</span> MultiWordSuggestion
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> PersonDTO personDTO <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> PersonMultiWordSuggestion<span style="color: #009900;">&#40;</span>PersonDTO user<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>user.<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: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> user.<span style="color: #006633;">getLastname</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, 
              user.<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: #0000ff;">&quot; &quot;</span> <span style="color: #339933;">+</span> user.<span style="color: #006633;">getLastname</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">personDTO</span> <span style="color: #339933;">=</span> user<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @return the personDTO
     */</span>
     <span style="color: #000000; font-weight: bold;">public</span> PersonDTO getPersonDTO<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> personDTO<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The super() call sets up the first parameter as the replacement String and the second parameter as the display string. You can of course change these.</p>
<p>Next we need to make our own Suggest Oracle. This is done relatively easy. My oracle is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.SuggestOracle</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author James Heggs - jheggs@axonbirch.com
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonNameSuggestOracle <span style="color: #000000; font-weight: bold;">extends</span> SuggestOracle
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>PersonMultiWordSuggestion<span style="color: #339933;">&gt;</span> personSuggestions <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> requestSuggestions<span style="color: #009900;">&#40;</span><span style="color: #003399;">Request</span> request, Callback callback<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Response resp <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Response<span style="color: #009900;">&#40;</span> matchingPeople<span style="color: #009900;">&#40;</span> request.<span style="color: #006633;">getQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
                                                      request.<span style="color: #006633;">getLimit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        callback.<span style="color: #006633;">onSuggestionsReady</span><span style="color: #009900;">&#40;</span>request, resp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * 
     * @param query The current text being entered into the suggest box
     * @param limit The maximum number of results to return 
     * @return A collection of people suggestions that match.
     */</span>
     <span style="color: #000000; font-weight: bold;">public</span> Collection<span style="color: #339933;">&lt;</span>PersonMultiWordSuggestion<span style="color: #339933;">&gt;</span> matchingPeople<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query, <span style="color: #000066; font-weight: bold;">int</span> limit<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
         List<span style="color: #339933;">&lt;</span>PersonMultiWordSuggestion<span style="color: #339933;">&gt;</span> matchingPeople <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>PersonMultiWordSuggestion<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span>limit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// only begin to search after the user has type two characters</span>
         <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> query.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
             <span style="color: #003399;">String</span> prefixToMatch <span style="color: #339933;">=</span> query.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
             <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
             <span style="color: #000066; font-weight: bold;">int</span> s <span style="color: #339933;">=</span> personSuggestions.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
             <span style="color: #666666; font-style: italic;">// Skip forward over all the names that don't match at the beginning of the array.</span>
             <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> s <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>personSuggestions.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDisplayString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span>prefixToMatch<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
             <span style="color: #009900;">&#123;</span>
                 i<span style="color: #339933;">++;</span>
             <span style="color: #009900;">&#125;</span>
&nbsp;
             <span style="color: #666666; font-style: italic;">// Now we are at the start of the block of matching names. Add matching names till we</span>
             <span style="color: #666666; font-style: italic;">// run out of names, stop finding matches, or have enough matches.</span>
             <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
             <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> s <span style="color: #339933;">&amp;&amp;</span> personSuggestions.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDisplayString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span>prefixToMatch<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> count <span style="color: #339933;">&lt;</span> limit<span style="color: #009900;">&#41;</span> 
             <span style="color: #009900;">&#123;</span>
                 matchingPeople.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span> personSuggestions.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                 i<span style="color: #339933;">++;</span>
                 count<span style="color: #339933;">++;</span>
             <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #009900;">&#125;</span>
&nbsp;
             <span style="color: #000000; font-weight: bold;">return</span> matchingPeople<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @param o 
         * @return
         * @see java.util.List#add(java.lang.Object)
         */</span>
         <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> add<span style="color: #009900;">&#40;</span>PersonMultiWordSuggestion o<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
             <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> personSuggestions <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
             <span style="color: #009900;">&#123;</span>
                personSuggestions <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>PersonMultiWordSuggestion<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</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;">return</span> personSuggestions.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * @param o
         * @return
         * @see java.util.List#remove(java.lang.Object)
         */</span>
         <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> remove<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
             <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> personSuggestions <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
             <span style="color: #009900;">&#123;</span>
                 <span style="color: #000000; font-weight: bold;">return</span> personSuggestions.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>o<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;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I think for most developers that enough code to get going but just to clear things up the following code snippets show the use of the DTO and SuggestBox as to how it could be used. Also in the code snippets I am assuming you are familar with GWT&#8217;s RPC architecture.</p>
<p>First an RPC call to fetch the DTO objects from a server (Production mode could ask for persistent objects from hibernate or something similar.)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
PersonNameSuggestOracle oracle <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PersonNameSuggestOracle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
SuggestBox nameSuggestBox <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SuggestBox<span style="color: #009900;">&#40;</span>oracle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">//fetch names</span>
  MyServiceAsync serviceRPC <span style="color: #339933;">=</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>MyService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  serviceRPC.<span style="color: #006633;">fetchPeople</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AsyncCallback<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>PersonDTO<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onFailure<span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> caught<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
   <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> onSuccess<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>PersonDTO<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> results<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> results <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> results.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> PersonDTO person <span style="color: #339933;">:</span> results <span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
      oracle.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PersonMultiWordSuggestion<span style="color: #009900;">&#40;</span>person<span style="color: #009900;">&#41;</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>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then for those interest snippet code on how to handle the selected suggestion</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">nameSuggestBox.<span style="color: #006633;">addEventHandler</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SuggestionHandler<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onSuggestionSelected<span style="color: #009900;">&#40;</span>SuggestionEvent event<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        PersonMultiWordSuggestion suggestion <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>PersonMultiWordSuggestion<span style="color: #009900;">&#41;</span>event.<span style="color: #006633;">getSelectedSuggestion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Do what you want with the suggestion and DTO</span>
        <span style="color: #666666; font-style: italic;">// suggestion.getPersonDTO</span>
&nbsp;
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Thats basically it. If people have any questions or ideas please post them as a comment in order to help others.</p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2008/08/25/gwt-suggestbox-backed-by-dto-model/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Hibernate, Spring, Google Web Toolkit &#8211; Part Three</title>
		<link>http://eggsylife.co.uk/2008/02/09/hibernate-spring-google-web-toolkit-part-three/</link>
		<comments>http://eggsylife.co.uk/2008/02/09/hibernate-spring-google-web-toolkit-part-three/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 09:52:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[hibernate annotations with gwt]]></category>
		<category><![CDATA[rpc over gwt]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[transactional database and GWT]]></category>

		<guid isPermaLink="false">http://eggsylife.co.uk/?p=22</guid>
		<description><![CDATA[The first thing we need to do in part three is begin GWT&#8217;s Remote Procedural Call (RPC) plumbing. We use the RPC calls to fire off Asynchronous events so that we can get data from our database. The calls go to the server effectively. Firstly I have made a package called com.company.client.rpc and this is [...]]]></description>
			<content:encoded><![CDATA[<p>The first thing we need to do in part three is begin GWT&#8217;s Remote Procedural Call (RPC) plumbing. We use the RPC calls to fire off Asynchronous events so that we can get data from our database. The calls go to the server effectively. Firstly I have made a package called <strong>com.company.client.rpc</strong> and this is where we&#8217;ll make our RPC interfaces.</p>
<p>Firstly make a interface called <strong>TeacherService</strong> as listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client.rpc</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.RemoteService</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TeacherService <span style="color: #000000; font-weight: bold;">extends</span> RemoteService
<span style="color: #009900;">&#123;</span>
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * @gwt.typeArgs &lt;com.company.client.dto.PupilDTO&gt;
 */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">List</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A few things to notice here are that the interface extends RemoteService which is a GWT class and is part of the RPC plumbing. Also you&#8217;ll note that the return type is not typed as in List <Object> this is because at the writing of this GWT didn&#8217;t support Java 6. Also the gwt.typeArgs defines to GWT the type that we expect to get back.</p>
<p>Now we need to make our Async version of the interface. Make a new interface within the same packaged named TeacherServiceAsync. The Async appendage is important because GWT uses this convention to identify async classes. The code is listed below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client.rpc</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.AsyncCallback</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> TeacherServiceAsync
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId, AsyncCallback callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice that we have changed the return type to void and added a parameter to the method signature that is of type AsyncCallback this is also very important and you&#8217;ll see why later. The callback parameter must always be last so if your methods take a few arguments make sure your AsyncCallback argument is last. Now to write the classes on the server side of code. Here we will drag some useful functionality from Spring and implement Transactional Database calls.</p>
<p>Firstly make a package called com.company.server.gwt. Then we can create our RemoteServiceServlet. The class beginnings is listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.server.gwt</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.dto.PupilDTO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.rpc.TeacherService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.server.rpc.RemoteServiceServlet</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TeacherServiceImpl <span style="color: #000000; font-weight: bold;">extends</span> RemoteServiceServlet <span style="color: #000000; font-weight: bold;">implements</span> TeacherService
<span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * 
  */</span>
 <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: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>PupilDTO<span style="color: #339933;">&gt;</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice we can fully type our list as we are coding server side code and that the interface extends RemoteServiceServlet which is a required part of the the RPC plumbing. For now leave that class there and we will make the database code.</p>
<p>Make a new package called com.company.server.domain (obviously package names are up to you my convention is hazy sometimes&#8230;) I tend to work with collections of data and have a convention that server classes extend java.util.List and then we can ask for any element from the list. Firstly make an interface called Pupil Collection that extends List. You can also use java generics as I have done if required. Code below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.server.domain</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> PupilCollection<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * 
  * @return The list associated with the class
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> getList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * Populate the list for the class with some pupils
  * 
  * @param teacherId
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we&#8217;ll write the implementing class and this will contain the true database calls to fetch data also any delegate methods for our List object. Code listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.server.domain</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Collection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ListIterator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.orm.hibernate3.support.HibernateDaoSupport</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.transaction.annotation.Transactional</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PupilCollectionImpl<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">extends</span> HibernateDaoSupport <span style="color: #000000; font-weight: bold;">implements</span> PupilCollection<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> list <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> List<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> getList<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> list<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 @Transactional<span style="color: #009900;">&#40;</span>readOnly<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">try</span>
  <span style="color: #009900;">&#123;</span>
   list <span style="color: #339933;">=</span> getHibernateTemplate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">findByNamedQueryAndNamedParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pupilsbyid&quot;</span>, <span style="color: #0000ff;">&quot;teacherId&quot;</span>, teacherId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
 <span style="color: #666666; font-style: italic;">/// DELEGATE METHODS REQUIRED FOR OUR LIST ////</span>
 <span style="color: #666666; font-style: italic;">/// NOT IMPLEMENTED AS NOT USED BY EXAMPLE ////</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> add<span style="color: #009900;">&#40;</span>T o<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><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> add<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index, T element<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
 <span style="color: #009900;">&#125;</span>
&nbsp;
...</pre></div></div>

<p>This is a very important class things to note are the use of the @Transactional annotation above the method. This alerts Spring that the method should be executed in one transaction. The second thing is Hibernate query call <strong>findByNamedQueryAndNamedParam(&#8220;pupilsbyid&#8221;, &#8220;teacherId&#8221;, teacherId)</strong> pupilsbyid is our query name, teacherId as String is the parameter name and teacherID as Integer is the actual ID we are looking for.</p>
<p>. Now to go ahead and write our query into our mapping file.</p>
<p>In the hibernate.cfg.xml file add the line:</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;mapping</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;database.hbm.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>This allows us to use a hibernate mapping file to put our queries into. Now in the src folder create a file called database.hbm.xml code listed below</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: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE hibernate-mapping</span>
<span style="color: #00bbdd;">    PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD//EN&quot;</span>
<span style="color: #00bbdd;">    &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hibernate-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;query</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pupilsbyid&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">  from com.company.server.persistent.Pupil as p</span>
<span style="color: #339933;">  where p.teacher.teacherId = :teacherId</span>
<span style="color: #339933;">  order by p.name ]]&gt;</span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hibernate-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You can now see our query name and the parameter specification as mentioned before.  This will get us all the pupils for a certain teacher.</p>
<p>Thats our server database code complete. Now we can go back to the unfinished RemoteServiceServlet class and use a bit of Spring magic to make the call. Firstly we need to define a bean for our PupilCollectionImpl so find the applicationContext.xml file that was created in the earlier tutorials and add the line:</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;pupilCollection&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.company.server.domain.PupilCollectionImpl&quot;</span> <span style="color: #000066;">scope</span>=<span style="color: #ff0000;">&quot;prototype&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;sessionFactory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;sessionFactory&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><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>Now thats done we need to write a way to get the beans, make a new package called com.company.spring and add the following class</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.spring</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.ApplicationContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.context.support.ClassPathXmlApplicationContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContextUtil
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> ApplicationContext context <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;">private</span> ContextUtil<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;">super</span><span style="color: #009900;">&#40;</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;">public</span> <span style="color: #000000; font-weight: bold;">static</span> ApplicationContext getContext<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span> 
 <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Load up our Application context</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>context <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #009900;">&#123;</span>
   context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathXmlApplicationContext<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;applicationContext.xml&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;">return</span> context<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This class is used to load our applicationContext and get any required beans. You can of course do this differently.</p>
<p>This allows us get access to the database methods we just wrote and also the database details through the use of referencing the session factory bean within the definition. Now to call trhe bean revisit the TeacherServiceImpl class and add the following lines:</p>
<pre>
public List<PupilDTO> getPupils(Integer teacherId)
 {
  List<PupilDTO> results = null;
  try
  {
   PupilCollection<?> collection = (PupilCollection<?>) ContextUtil.getContext().getBean("pupilCollection");
   collection.getPupils(teacherId);

   results = new ArrayList<PupilDTO>();

   for ( Iterator<?> it = collection.getList().iterator(); it.hasNext(); )
   {
    Pupil pupil = (Pupil) it.next();
    PupilDTO dto = new PupilDTO();

    BeanUtils.copyProperties(dto, pupil);

    results.add(dto);
   }
  }
  catch(Exception e)
  {
   e.printStackTrace();
   throw new RuntimeException(e);
  }

  return results;
 }
</pre>
<p>Notice the name of the bean we are getting pupilCollection&#8217; which we defined in our applicationContext. Is it coming together now?<br />
Thats basically our server side code now complete. We now have some methods that we can call upon to load data. Woohoo!</p>
<p>The next thing to do is perform the calls from the client end somehow. For this I use an MVC approach and implement the observer<br />
pattern as specified by the <a href="http://www.amazon.co.uk/Design-patterns-elements-reusable-object-oriented/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&#038;s=gateway&#038;qid=1202591754&#038;sr=8-1" target="_blank">Gang of 4 Design Patterns</a>.</p>
<p>Firstly make a package named com.company.client.model and in there add two interfaces <strong>Observer</strong> and <strong>Subject</strong>. Code listed below:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client.model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> Subject
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addObserver<span style="color: #009900;">&#40;</span> <span style="color: #003399;">Observer</span> o <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> removeObserver<span style="color: #009900;">&#40;</span> <span style="color: #003399;">Observer</span> o <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<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;">package</span> <span style="color: #006699;">com.company.client.model</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> <span style="color: #003399;">Observer</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> update<span style="color: #009900;">&#40;</span> Subject o <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next make our model that implements Subject. This is used so that we can make the RPC calls from the client end and successfully update GUI<br />
views. I have made a <strong>TeacherModel</strong> class that implements Subject. Code is listed below.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client.model</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.rpc.TeacherService</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.rpc.TeacherServiceAsync</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.core.client.GWT</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.AsyncCallback</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.rpc.ServiceDefTarget</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TeacherModel <span style="color: #000000; font-weight: bold;">implements</span> Subject
<span style="color: #009900;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> pupils <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;">protected</span> <span style="color: #003399;">ArrayList</span> observers <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">///// Observer Methods ////////</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addObserver<span style="color: #009900;">&#40;</span><span style="color: #003399;">Observer</span> o<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> observers <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   observers <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  observers.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <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> removeObserver<span style="color: #009900;">&#40;</span><span style="color: #003399;">Observer</span> o<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> observers <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   observers.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>o<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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> notifyObservers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">Iterator</span> it <span style="color: #339933;">=</span> observers.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> it.<span style="color: #006633;">hasNext</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: #003399;">Observer</span> o <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #003399;">Observer</span> <span style="color: #009900;">&#41;</span> it.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
              o.<span style="color: #006633;">update</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</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: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> getPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> teacherId<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  TeacherServiceAsync teacherService <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TeacherServiceAsync<span style="color: #009900;">&#41;</span> GWT.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>TeacherService.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   ServiceDefTarget endpoint <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ServiceDefTarget<span style="color: #009900;">&#41;</span> teacherService<span style="color: #339933;">;</span>
   <span style="color: #003399;">String</span> moduleRelativeURL <span style="color: #339933;">=</span> GWT.<span style="color: #006633;">getModuleBaseURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;teachers&quot;</span><span style="color: #339933;">;</span>
   endpoint.<span style="color: #006633;">setServiceEntryPoint</span><span style="color: #009900;">&#40;</span>moduleRelativeURL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   teacherService.<span style="color: #006633;">getPupils</span><span style="color: #009900;">&#40;</span>teacherId, <span style="color: #000000; font-weight: bold;">new</span> AsyncCallback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onFailure<span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> caught<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// TODO Auto-generated method stub</span>
&nbsp;
   <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> onSuccess<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> result<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span> 
    pupils <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> result<span style="color: #339933;">;</span>
&nbsp;
    notifyObservers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #009900;">&#125;</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;">public</span> <span style="color: #003399;">List</span> getPupils<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> pupils<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> setPupils<span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span> pupils<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;">pupils</span> <span style="color: #339933;">=</span> pupils<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I won&#8217;t go into details about the implementation of the design pattern for that read the book its worth it! The getPupils method is the important one this is where we perform the RPC call, notice we look for a URL of &#8220;teachers&#8221; this is defined in the gwt.xml file so lets define it now. In the MyApplication.gwt.xml file add the line:</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;servlet</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/teachers&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.company.server.gwt.TeacherServiceImpl&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>This makes that RPC now work. Now inspect the anonymous inner callback class in my implementation this is used to update and notify any observers on a successful call. Also note you can cast the result to the type it is meant to be. For example a save method could return a boolean.</p>
<p>At this stage you can test the call to ensure that it is working by simply making a new TeacherModel and calling getPupils. The final step is to write the<br />
client GUI code. I have wrote a simply GUI that takes an ID and performs a search for pupils when the users click search, when the search has finished the view is updated in a GWT way. The code is below and may help bring things together for the whole Async way of doing things.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.company.client</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.dto.PupilDTO</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.model.Observer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.model.Subject</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.company.client.model.TeacherModel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.core.client.EntryPoint</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.ClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.HTML</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.HorizontalPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.RootPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.TextBox</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.VerticalPanel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.gwt.user.client.ui.Widget</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyApplication <span style="color: #000000; font-weight: bold;">implements</span> EntryPoint, <span style="color: #003399;">Observer</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">private</span> TeacherModel model <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;">private</span> VerticalPanel display <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;">private</span> VerticalPanel resultsPanel <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
 <span style="color: #008000; font-style: italic; font-weight: bold;">/**
  * This is the entry point method.
  */</span>
 <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onModuleLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  model <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TeacherModel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  display <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VerticalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  model.<span style="color: #006633;">addObserver</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  HorizontalPanel searchPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HorizontalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">final</span> TextBox teacherIdBox<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextBox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Button</span> button <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Button</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Search&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  button.<span style="color: #006633;">addClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ClickListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span>Widget sender<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    resultsPanel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HTML</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Searching....&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    model.<span style="color: #006633;">getPupils</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>teacherIdBox.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  searchPanel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>teacherIdBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  searchPanel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>button<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  resultsPanel <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VerticalPanel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  display.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>searchPanel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  display.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>resultsPanel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  RootPanel.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;database&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>display<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;">public</span> <span style="color: #000066; font-weight: bold;">void</span> update<span style="color: #009900;">&#40;</span>Subject o<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> model.<span style="color: #006633;">getPupils</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;">&amp;&amp;</span> model.<span style="color: #006633;">getPupils</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   resultsPanel.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003399;">Iterator</span> it <span style="color: #339933;">=</span> model.<span style="color: #006633;">getPupils</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> it.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    PupilDTO dto <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>PupilDTO<span style="color: #009900;">&#41;</span>it.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    resultsPanel.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HTML</span><span style="color: #009900;">&#40;</span>dto.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope this tutorial has helped clear up some issues. The final tutorial will explain how make the application work as a live application and not just in GWT hosted mode. The Eclipse project can be downloaded here and can be used as a template for projects. I would still urge people to read the tutorial.</p>
<p><a href="http://eggsylife.blogspot.com/2008/09/hibernate-spring-google-web-toolkit.html">Part four is now available</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eggsylife.co.uk/2008/02/09/hibernate-spring-google-web-toolkit-part-three/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
