<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Gridshore software engineering weblog - ajax</title>
    <link>http://www.gridshore.nl/blog/</link>
    <description>This weblog is about everything that has to do with software engineering. It will focus on items like Springframework, acegi, hibernate and other tools to help creating good software</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2.1 - http://www.s9y.org/</generator>
    <pubDate>Tue, 29 Jan 2008 10:27:03 GMT</pubDate>

    <image>
        <url>http://www.gridshore.nl/blog/templates/gridshore/img/s9y_banner_small.png</url>
        <title>RSS: Gridshore software engineering weblog - ajax - This weblog is about everything that has to do with software engineering. It will focus on items like Springframework, acegi, hibernate and other tools to help creating good software</title>
        <link>http://www.gridshore.nl/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Last entry ...</title>
    <link>http://www.gridshore.nl/blog/index.php?/archives/74-Last-entry-....html</link>
            <category>acegi</category>
            <category>ajax</category>
            <category>Announcements</category>
            <category>Books</category>
            <category>gridshore</category>
            <category>Java</category>
            <category>News</category>
            <category>spring-osgi</category>
            <category>Springframework</category>
            <category>Technology</category>
            <category>Webservices</category>
            <category>Websites&amp;products</category>
    
    <comments>http://www.gridshore.nl/blog/index.php?/archives/74-Last-entry-....html#comments</comments>
    <wfw:comment>http://www.gridshore.nl/blog/wfwcomment.php?cid=74</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.gridshore.nl/blog/rss.php?version=2.0&amp;type=comments&amp;cid=74</wfw:commentRss>
    

    <author>nospam@example.com (Jettro Coenradie)</author>
    <content:encoded>
    Welcome to the last entry of this blog. No I am not quitting, I am just moving. I just installed a new blog software framework. I was starting to dislike the way to interact and I wanted something that contained more out of the box. I am in the middle of moving to wordpress software. There is a very good reason to do this. I had found a great tool on the mac called MarsEdit. And again this could not be used with serendipity. I hope I did make a good choice. Since there is a lot of information in the old blog, I did not take this blog offline. It will stay to exist, but I will not make changes there anymore.&lt;br /&gt;
&lt;br /&gt;
I hope to see you at the new version of the blog (check the page at http://www.gridshore.nl). You can attach you feedreader to the following url: feed://www.gridshore.nl/feed/ 
    </content:encoded>

    <pubDate>Sat, 19 Jan 2008 20:58:56 +0100</pubDate>
    <guid isPermaLink="false">http://www.gridshore.nl/blog/index.php?/archives/74-guid.html</guid>
    
</item>
<item>
    <title>Rowing the Google Web Toolkit boat with intellij</title>
    <link>http://www.gridshore.nl/blog/index.php?/archives/69-Rowing-the-Google-Web-Toolkit-boat-with-intellij.html</link>
            <category>ajax</category>
            <category>Java</category>
    
    <comments>http://www.gridshore.nl/blog/index.php?/archives/69-Rowing-the-Google-Web-Toolkit-boat-with-intellij.html#comments</comments>
    <wfw:comment>http://www.gridshore.nl/blog/wfwcomment.php?cid=69</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.gridshore.nl/blog/rss.php?version=2.0&amp;type=comments&amp;cid=69</wfw:commentRss>
    

    <author>nospam@example.com (Jettro Coenradie)</author>
    <content:encoded>
    The last month(s) I have been working on multiple &lt;a href=&quot;http://code.google.com/webtoolkit/&quot;  title=&quot;gwt&quot;&gt;Google Web Toolkit&lt;/a&gt; implementations. I must admit that the implementations are not very big. They are mostly small applications I needed for some reason. One of them is a Raffle system, there is one with a large amount of data on a screen that should be editable as well. In this blog item I will share some experiences I have gained using the Google Web Toolkit with &lt;a href=&quot;http://code.google.com/p/gwt-maven/&quot;  title=&quot;maven gwt&quot;&gt;maven2&lt;/a&gt;, &lt;a href=&quot;http://www.jetbrains.com/idea/nextversion/&quot;  title=&quot;intellij&quot;&gt;JetBrains IntelliJ&lt;/a&gt;. The applications can interact with a standard GWT servlet, or with the springframework and security via spring security (acegi). I also experimented with a nice GUI framework called &lt;a href=&quot;http://code.google.com/p/gwt-ext/&quot;  title=&quot;gwt-ext&quot;&gt;gwt-ext&lt;/a&gt;. Finally, I also used the Google Web Toolkit in a sample we created for spring osgi. So please continue reading, most sources can be found in in my&lt;a href=&quot;http://code.google.com/p/gridshore/&quot;  title=&quot;google code for gridshore&quot;&gt; code repository &lt;/a&gt;at google.&lt;br /&gt;
In this blog item I will mostly look at IntelliJ, I will create new blog items about using eclipse and maven as well.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 1 - Creating a project skeleton&lt;/strong&gt;&lt;br /&gt;
&lt;p&gt;&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 110px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://www.gridshore.nl/blog/uploads/gwt/intellijmodulesettingsgwt.jpg&#039; onclick=&quot;F1 = window.open(&#039;/blog/uploads/gwt/intellijmodulesettingsgwt.jpg&#039;,&#039;Zoom&#039;,&#039;height=444,width=615,top=185.5,left=340,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes&#039;); return false;&quot;&gt;&lt;!-- s9ymdb:28 --&gt;&lt;img width=&#039;110&#039; height=&#039;79&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijmodulesettingsgwt.serendipityThumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;new gwt module wizzard&lt;/div&gt;&lt;/div&gt;If you just want to play around and you have IntelliJ, I recommend to use the new project wizzard from intellij. Just create a new Java Project and select Google Web Toolkit in the desired technologies section. Go to the module settings and point to the right direction of you gwt install. Now you can start adding modules, remote services, etc.&lt;/p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 2 - Adding the module and entry point&lt;/strong&gt;&lt;br /&gt;
&lt;div class=&quot;serendipity_imageComment_right&quot; style=&quot;width: 74px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://www.gridshore.nl/blog/uploads/gwt/intellijstructurenewmodule.jpg&#039; onclick=&quot;F1 = window.open(&#039;/blog/uploads/gwt/intellijstructurenewmodule.jpg&#039;,&#039;Zoom&#039;,&#039;height=479,width=327,top=168,left=484,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes&#039;); return false;&quot;&gt;&lt;!-- s9ymdb:29 --&gt;&lt;img width=&#039;74&#039; height=&#039;110&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijstructurenewmodule.serendipityThumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;generated gwt module files&lt;/div&gt;&lt;/div&gt;Start by adding a package, select src and alt+insert. Select package, enter the package name. Then select that package and again alt-insert. Now choose the gwt&gt;gwt module. Give the name you think is right for your project, in my case &lt;em&gt;Raffle&lt;/em&gt;. This step generates multiple files:&lt;br /&gt;
Raffle.gwt.xml - the configuration file for the module with a reference to the entry point.&lt;br /&gt;
Raffle.java - in the client package, this is the entry point for the gwt application.&lt;br /&gt;
Raffle.html - html file in the public folder that is called by the browser with a javascript that starts the gwt application.&lt;br /&gt;
Raffle.css - stylesheet referenced by the html file that is also in the public folder.&lt;br /&gt;
&lt;br /&gt;
Everthing in the client folder is compiled to JavaScript, be sure there is nog Java 5 features in here, this is not (yet) supported. The public folder is exposed using the webserver as static files. Nothing happens to them. You can put images in here as well. Finally there is a server folder. This is in the end a plain java folder that contains the implementations of remote services. More on that later.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 3 - Test the setup we have created&lt;/strong&gt;&lt;br /&gt;
&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 110px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://www.gridshore.nl/blog/uploads/gwt/intellijaddgwtrunconfiguration.jpg&#039; onclick=&quot;F1 = window.open(&#039;/blog/uploads/gwt/intellijaddgwtrunconfiguration.jpg&#039;,&#039;Zoom&#039;,&#039;height=522,width=615,top=146.5,left=340,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes&#039;); return false;&quot;&gt;&lt;!-- s9ymdb:30 --&gt;&lt;img width=&#039;110&#039; height=&#039;93&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijaddgwtrunconfiguration.serendipityThumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;create new run configuration&lt;/div&gt;&lt;/div&gt;Time to start the test. We need to create a configuration. Press alt+shift+f10 and &#039;edit configurations&#039;. In the next screen add the + sign to create a new configuration and choose GWT Configuration. Give the configuration a good name. Other than that, the defaults should be fine. Now you can run the application by clicking the green run arrow or shift + f10. You can see the result in the icon on the right.&lt;div class=&quot;serendipity_imageComment_right&quot; style=&quot;width: 110px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://www.gridshore.nl/blog/uploads/gwt/intellijgwtrunfirst.jpg&#039; onclick=&quot;F1 = window.open(&#039;/blog/uploads/gwt/intellijgwtrunfirst.jpg&#039;,&#039;Zoom&#039;,&#039;height=515,width=815,top=150,left=240,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes&#039;); return false;&quot;&gt;&lt;!-- s9ymdb:34 --&gt;&lt;img width=&#039;110&#039; height=&#039;69&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijgwtrunfirst.serendipityThumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;running the application&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 4 - Adding stuff to the screen.&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;Step 4.1 - Add the menu&lt;/strong&gt;&lt;br /&gt;
The total screen will consist of two panels, one containing the menu, the other is the content panel in which all menu actions take place.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
public void onModuleLoad() {&lt;br /&gt;
  ScrollPanel contentContent = new ScrollPanel();&lt;br /&gt;
  MenuBar menuBar = createMenuBar(contentContent);&lt;br /&gt;
  RootPanel.get().add(menuBar);&lt;br /&gt;
  RootPanel.get().add(contentPanel);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private MenuBar createMenuBar(final ScrollPanel contentPanel) {&lt;br /&gt;
  ...&lt;br /&gt;
    menuBar.addItem(&quot;List Names&quot;, new Command() {&lt;br /&gt;
      public void execute() {&lt;br /&gt;
        contentPanel.setWidget(createListNames(contentPanel));&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
private Panel createListNames(final ScrollPanel contentPanel) {&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
The code shows how to create the MenuBar and how to add an item. This is not a very thorough example and as you can see I did not implement the method createListNames. Before I do this I need to explain remoting which I will do next. The sample up till now does show how to add an a menu and how to add items to the menu. Look at the way to create a command when the menu item is clicked. By using the method setWidget on the content panel we can change the content on the page when clicking a menu item.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 4.2 - Doing some remoting&lt;/strong&gt;&lt;br /&gt;
&lt;div class=&quot;serendipity_imageComment_left&quot; style=&quot;width: 110px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;a class=&#039;serendipity_image_link&#039; href=&#039;http://www.gridshore.nl/blog/uploads/gwt/intellijcreateremoteservice.jpg&#039; onclick=&quot;F1 = window.open(&#039;/blog/uploads/gwt/intellijcreateremoteservice.jpg&#039;,&#039;Zoom&#039;,&#039;height=515,width=815,top=150,left=240,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes&#039;); return false;&quot;&gt;&lt;!-- s9ymdb:36 --&gt;&lt;img width=&#039;110&#039; height=&#039;69&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijcreateremoteservice.serendipityThumb.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;Create a new remote service&lt;/div&gt;&lt;/div&gt;This is the moment Intellij will also help you a lot. Select the package where you stored your client gwt module. alt + insert will popup a menu. Select the Google Web Toolkit &gt; GWT Remote Service. The following file will be generated when you create the RaffleRemoteService:&lt;br /&gt;
&lt;br /&gt;
In the client package&lt;br /&gt;
RaffleRemoteService - Interface containing a static internal class &lt;strong&gt;App&lt;/strong&gt; with a utility method getInstance to get a RaffleRemoteServiceAsync. Check the code later on.&lt;br /&gt;
RaffleRemoteServiceAsync - Interface that has the same methods as the RaffleRemoteService with one extra parameter of type AsyncCallback.&lt;br /&gt;
&lt;br /&gt;
In the server package&lt;br /&gt;
RaffleRemoteServiceImpl that implements RaffleRemoteService and is a subclass of RemoteServiceServlet, a google web toolkit provided servlet. This servlet is also automatically configured in the module configuration file &#039;Raffle.gwt.xml&#039;. The following lines are added.&lt;br /&gt;
&lt;br /&gt;
&amp;#160;servlet path=&quot;/nl.gridshore.samples.gwt.simple.Raffle/RaffleRemoteService&quot;&lt;br /&gt;
    class=&quot;nl.gridshore.samples.gwt.simple.server.RaffleRemoteServiceImpl&quot;/&gt;&lt;br /&gt;
&lt;br /&gt;
Want to see some intellij magic? Let&#039;s add a method to the RaffleRemoteService for obtaining a list of names.&lt;br /&gt;
&lt;!-- s9ymdb:38 --&gt;&lt;img width=&#039;775&#039; height=&#039;209&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://www.gridshore.nl/blog/uploads/gwt/intellijaddingmethodtoremoteservice.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
As you can see on the image there is an error. Intellij asks you if you want to synchronise the remote service with the asynchronous service. Click ant + enter and the interfaces are in sync again. There is more in the image. Check the return argument &lt;em&gt;ArrayList&lt;/em&gt;. This is not a java 5 collection, gwt cannot handle that. But we do need to tell what kind of objects are in the ArrayList. This is why we need the annotation @gwt.typeArgs &lt;java.lang.String&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Step 4.3 - Doing some styling&lt;/strong&gt;&lt;br /&gt;
You can add styling via the style sheet. Almost every widget has it&#039;s own styling and of course you can add a style name to every widget you create. Some of the basic styles are:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
.gwt-Button {}&lt;br /&gt;
.gwt-Label {}&lt;br /&gt;
.gwt-TextBox {margin-left:20}&lt;br /&gt;
.gwt-TextBox-readonly {}&lt;br /&gt;
&lt;br /&gt;
.gwt-MenuBar {}&lt;br /&gt;
.gwt-MenuBar .gwt-MenuItem {}&lt;br /&gt;
.gwt-MenuBar .gwt-MenuItem-selected {}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
That is about it for now, hope this helps, you can extract the important information if you want to use eclipse. Next time I will write something about using maven2 and a special toolkit called gwt-ext. You can find the complete source code online: &lt;a href=&quot;http://gridshore.googlecode.com/svn/trunk/Raffle/&quot;  title=&quot;code&quot;&gt;http://gridshore.googlecode.com/svn/trunk/Raffle/&lt;/a&gt; 
    </content:encoded>

    <pubDate>Sun, 14 Oct 2007 09:11:49 +0200</pubDate>
    <guid isPermaLink="false">http://www.gridshore.nl/blog/index.php?/archives/69-guid.html</guid>
    
</item>
<item>
    <title>Creating an autocomplete with Spring and DWR</title>
    <link>http://www.gridshore.nl/blog/index.php?/archives/52-Creating-an-autocomplete-with-Spring-and-DWR.html</link>
            <category>ajax</category>
            <category>Java</category>
    
    <comments>http://www.gridshore.nl/blog/index.php?/archives/52-Creating-an-autocomplete-with-Spring-and-DWR.html#comments</comments>
    <wfw:comment>http://www.gridshore.nl/blog/wfwcomment.php?cid=52</wfw:comment>

    <slash:comments>49</slash:comments>
    <wfw:commentRss>http://www.gridshore.nl/blog/rss.php?version=2.0&amp;type=comments&amp;cid=52</wfw:commentRss>
    

    <author>nospam@example.com (Jettro Coenradie)</author>
    <content:encoded>
    There is a lot of talk around the web about autocomplete with ajax. I have blogged about a solution with ajaxtags and spring before (&lt;a href=&quot;http://www.gridshore.nl/blog/index.php?/archives/29-Doing-ajax-with-ajaxtags-and-springframework.html&quot;&gt;link&lt;/a&gt;). It is a nice solutions that works pretty well. Still I did not feel right to have to do a lot of configuration within spring and do something special in your normal code. I also had a look at &lt;a href=&quot;http://getahead.ltd.uk/dwr/&quot;  title=&quot;dwr homepage&quot;&gt;dwr&lt;/a&gt;. This is a nice library that lets you expose a serverside service to your javascript. A number of javascript libraries are generated runtime, you can use these libraries from your scripts within the browser. There is a nice integration with &lt;a href=&quot;http://script.aculo.us/&quot;  title=&quot;script.aculo.us&quot;&gt;script.aculo.us&lt;/a&gt;. Now you can use a lot of components out of the box. Next step, use the script.aculo.us autocomplete component with dwr. Well that is easy said. There are some blog items on the web that tell you how to do this. The best way is to have a look at some sample code &lt;a href=&quot;http://bram.jteam.nl/index.php/2006/06/19/springone-dwr-spring-presentation/trackback/&quot;  title=&quot;Bram smeets Blog&quot;&gt;Bram smeets&lt;/a&gt; made on his blog. I used his code to create a sample that uses maven to build and package. I also used the callisto ide, works very good as well. I would not try the maven plugin yet, I did but it fails for now.&lt;br /&gt;
&lt;br /&gt;
After this rather long introduction, time to get the coding done.&lt;br /&gt;
&lt;b&gt;Step1&lt;/b&gt;&lt;br /&gt;
Get your environment in place. Run the maven archetype command to create a webproject template. Alter some of the default values to make it your project and put in dependencies on the following libraries to your pom.xml file:&lt;br /&gt;
&lt;i&gt;spring-webmvc-1.2.7&lt;/i&gt; (org.springframework)&lt;br /&gt;
&lt;i&gt;dwr-1.1.1&lt;/i&gt; (uk.ltd.getahead)&lt;br /&gt;
Execute the command to setup your eclipse environment and startup eclipse.&lt;br /&gt;
&lt;br /&gt;
commands:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
mvn archetype:create -DgroupId=nl.gridshore.ajaxdwrsample -DartifactId=ajaxdwrsample -DarchetypeArtifactId=maven-archetype-webapp&lt;br /&gt;
mvn -Dwtpversion=1.0 eclipse:eclipse&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 2&lt;/b&gt;&lt;br /&gt;
Time to explain a little bid what the application is going to do. Actually there is two phases in the application. First search for a known postalcode. If you have found the right one and pushed the search button, the accompanying address is obtained. Sounds easy doesn&#039;t it?&lt;br /&gt;
We are going to expose a service object with two methods:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
public interface RemoteAddressService {&lt;br /&gt;
  public AddressTO findAddressByPostalCode(String postalCode);&lt;br /&gt;
  public List findCompletePostalCodes(String partPostalCode);&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
It should be obvious what the implementation of this interface should do. To be able to do an easy test, I created a mock implementation for this interface. The mock contains a hashtable with some postal codes as a key and the belonging address as the value. The two methods mentioned before use this hashmap to return all postalcodes or the address for a specific postal code.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
public class MockRemoteAddressServiceImpl implements RemoteAddressService  {&lt;br /&gt;
  private Map addressByPostalCode = new HashMap();&lt;br /&gt;
  public void init() {&lt;br /&gt;
    ...&lt;br /&gt;
    addressByPostalCode.put(&quot;1234AA&quot;, new AddressTO(&quot;streetone&quot;,&quot;1&quot;,&quot;cityone&quot;,&quot;1234AA&quot;));&lt;br /&gt;
    ...&lt;br /&gt;
  }&lt;br /&gt;
  public AddressTO findAddressByPostalCode(final String postalCode) {&lt;br /&gt;
    return (AddressTO)addressByPostalCode.get(postalCode);&lt;br /&gt;
  }&lt;br /&gt;
  public List findCompletePostalCodes(final String partPostalCode) {&lt;br /&gt;
    Set keys = addressByPostalCode.keySet();&lt;br /&gt;
    List retKeys = new ArrayList();&lt;br /&gt;
    for (Iterator iter = keys.iterator();iter.hasNext();) {&lt;br /&gt;
      String key = (String)iter.next();&lt;br /&gt;
      retKeys.add(key);&lt;br /&gt;
    }&lt;br /&gt;
    return retKeys;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
Fianlly there is a transferobject called AddressTO that contains the following 4 fields: streetname, houseNumber, city, postalCode. Download the source to have a look. &lt;br /&gt;
We have created the interface and an implementation. Time to do some spring configuration. We only need to create one bean, therefore the config file is very easy&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;beans&gt;&lt;br /&gt;
  &amp;lt;bean id=&quot;addressServiceFacade&quot;&lt;br /&gt;
    class=&quot;nl.gridshore.ajaxdwrsample.service.impl.MockRemoteAddressServiceImpl&quot;&lt;br /&gt;
    init-method=&quot;init&quot;/&gt;&lt;br /&gt;
&amp;lt;/beans&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Step 3&lt;/b&gt;&lt;br /&gt;
After this everything is in place to configure dwr to expose the spring bean. To be able to use dwr, we first need to add the dwr servlet to the web.xml file and load the spring context:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;context-param&gt;&lt;br /&gt;
  &amp;lt;param-name&gt;contextConfigLocation&amp;lt;/param-name&gt;&lt;br /&gt;
  &amp;lt;param-value&gt;/WEB-INF/applicationContext.xml&amp;lt;/param-value&gt;&lt;br /&gt;
&amp;lt;/context-param&gt;&lt;br /&gt;
&amp;lt;listener&gt;&lt;br /&gt;
  &amp;lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&amp;lt;/listener-class&gt;&lt;br /&gt;
&amp;lt;/listener&gt;&lt;br /&gt;
&amp;lt;servlet&gt;&lt;br /&gt;
  &amp;lt;servlet-name&gt;dwr&amp;lt;/servlet-name&gt;&lt;br /&gt;
  &amp;lt;servlet-class&gt;uk.ltd.getahead.dwr.DWRServlet&amp;lt;/servlet-class&gt;&lt;br /&gt;
  &amp;lt;init-param&gt;&lt;br /&gt;
    &amp;lt;param-name&gt;debug&amp;lt;/param-name&gt;&lt;br /&gt;
    &amp;lt;param-value&gt;true&amp;lt;/param-value&gt;&lt;br /&gt;
  &amp;lt;/init-param&gt;&lt;br /&gt;
&amp;lt;/servlet&gt;&lt;br /&gt;
&amp;lt;servlet-mapping&gt;&lt;br /&gt;
  &amp;lt;servlet-name&gt;dwr&amp;lt;/servlet-name&gt;&lt;br /&gt;
  &amp;lt;url-pattern&gt;/dwr/*&amp;lt;/url-pattern&gt;&lt;br /&gt;
&amp;lt;/servlet-mapping&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
Dwr uses a configuration file to configure the beans that are exposed to your javascripts. This file is next to web.xml and is called dwr.xml.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;dwr&gt;&lt;br /&gt;
  &amp;lt;allow&gt;&lt;br /&gt;
    &amp;lt;create creator=&quot;spring&quot; javascript=&quot;AddressServiceFacade&quot;&gt;&lt;br /&gt;
      &amp;lt;param name=&quot;beanName&quot; value=&quot;addressServiceFacade&quot;/&gt;&lt;br /&gt;
    &amp;lt;/create&gt;&lt;br /&gt;
    &amp;lt;convert converter=&quot;bean&quot; match=&quot;nl.gridshore.ajaxdwrsample.to.AddressTO&quot;/&gt;&lt;br /&gt;
  &amp;lt;/allow&gt;&lt;br /&gt;
&amp;lt;/dwr&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
By default you allow all methods to be called, you should allow only the real ajax usable methods. The create element is like the constructor, I tell dwr to use spring to create the javascript object AddressServiceFacade based on the spring bean addressServiceFacade. Because a use a transfer object for the address I also need the converter.&lt;br /&gt;
Everything is ready to do the first test. Deploy the application to tomcat and call the following url: http://localhost:8080/ajaxdwrsample/drw&lt;br /&gt;
You should get a page with a link to AddressServiceFacade, click this link and have a look at the next page:&lt;br /&gt;
&lt;div class=&quot;serendipity_imageComment_center&quot; style=&quot;width: 600px&quot;&gt;&lt;div class=&quot;serendipity_imageComment_img&quot;&gt;&lt;img width=&#039;600&#039; height=&#039;436&#039;  src=&quot;http://www.gridshore.nl/blog/uploads/ajaxdwrsample_dwrtestpage.gif&quot; alt=&quot;&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;serendipity_imageComment_txt&quot;&gt;test page of dwr&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
On this screen you can test your dwr ajax service. Use the execute buttons and input boxes to test the services (see the red box). Great isn&#039;t it?&lt;br /&gt;
&lt;b&gt;Step 4&lt;/b&gt;&lt;br /&gt;
And now for the webpages. First add the script libraries to your war file. I added the Prototype script and the script.aculo.us. to the folder &quot;scripts&quot;. Next to that I added to style sheets (I copied all these files from the sample by Bram Smeets). Out of the box there is no support in script.aculo.us for autocomplete via dwr. Therefore I used the excellent component from Bram to  implement it. The component resides in the &quot;autocomplete.js&quot; file. Finally the index.jsp that implements the real automcomplete component.&lt;br /&gt;
The includes:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/ajaxdwrsample/styles/autocomplete.css&quot;/&gt;&lt;br /&gt;
&amp;lt;script type=&#039;text/javascript&#039; src=&#039;/ajaxdwrsample/dwr/interface/&lt;b&gt;AddressServiceFacade.js&lt;/b&gt;&#039;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&#039;text/javascript&#039; src=&#039;/ajaxdwrsample/dwr/engine.js&#039;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&#039;text/javascript&#039; src=&#039;/ajaxdwrsample/dwr/util.js&#039;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;/ajaxdwrsample/scripts/prototype/prototype.js&quot;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;/ajaxdwrsample/scripts/script.aculo.us/effects.js&quot;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;/ajaxdwrsample/scripts/script.aculo.us/controls.js&quot;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;/ajaxdwrsample/scripts/autocomplete.js&quot;&gt;&amp;lt;/script&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
Important in the includes is the AddressServiceFacade, this is the generated script file by dwr based on the dwr.xml file. There we configured this name &lt;b&gt; ... javascript=&quot;AddressServiceFacade&quot; ...&lt;/b&gt;. Now the standard scripts are in place, do the html thing:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;input id=&quot;searchPostalCode&quot; type=&quot;text&quot; /&gt;&lt;br /&gt;
&amp;lt;input type=&quot;button&quot; value=&quot;Search&quot; onclick=&quot;handleAddClick();&quot;/&gt;&lt;br /&gt;
&amp;lt;div id=&quot;postalCodeList&quot; class=&quot;auto_complete&quot;&gt;&amp;lt;/div&gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot;&gt;&lt;br /&gt;
   new Autocompleter.DWR(&#039;searchPostalCode&#039;, &#039;postalCodeList&#039;, updateList,{ valueSelector: nameValueSelector, partialChars: 0 });&lt;br /&gt;
&amp;lt;/script&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
The constructor for the autocomplete component has 4 parameters:&lt;br /&gt;
&lt;ol&gt;&lt;br /&gt;
&lt;li&gt;searchPostalCode - Field to obtain the string from that has to autocompleted&lt;/li&gt;&lt;br /&gt;
&lt;li&gt;postalCodeList - Id of the div that will be filled with the found autocomplete items&lt;/li&gt;&lt;br /&gt;
&lt;li&gt;updateList - name of the script to use as callback function by the autocomplete script&lt;/li&gt;&lt;br /&gt;
&lt;li&gt;Options to pass to the autocomplete script&lt;/li&gt;&lt;br /&gt;
&lt;/ol&gt;&lt;br /&gt;
The callback function looks like this:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
function updateList(autocompleter, token) {&lt;br /&gt;
   AddressServiceFacade.findCompletePostalCodes(token, function(data) {   &lt;br /&gt;
      autocompleter.setChoices(data) &lt;br /&gt;
   });&lt;br /&gt;
}&lt;br /&gt;
function nameValueSelector(tag){&lt;br /&gt;
   return tag;&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
Doesn&#039;t look very difficult, does it? Beware of the function nameValueSelector, it receives a tag object. This can be a simple object (like in my case, a string). It can also be a javabean representation, then you need an extra method to obtain the property to show in the autocomplete box. If you return a list with AddressTO objects and want to show the postalCode of the address, this line would be : return tag.postalCode.&lt;br /&gt;
The autocomplete box will now look like the following image:&lt;br /&gt;
&lt;img width=&#039;400&#039; height=&#039;294&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://www.gridshore.nl/blog/uploads/ajaxdwrsample_autocomplete.gif&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
Your autocomplete is done, there is one extra thing in the sample. You can select the postal code and look for the belonging address. That is done the with the following piece of html and javascript.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&amp;lt;span id=&quot;streetname&quot;&gt;&amp;lt;/span&gt;&amp;#160;&amp;lt;span id=&quot;houseNumber&quot;&gt;&amp;lt;/span&gt;&amp;lt;br/&gt;&lt;br /&gt;
&amp;lt;span id=&quot;postalCode&quot;&gt;&amp;lt;/span&gt;&amp;lt;br/&gt;&lt;br /&gt;
&amp;lt;span id=&quot;city&quot;&gt;&amp;lt;/span&gt;&amp;lt;br/&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
The id&#039;s of the span elements resemble the fields of the AddressTO javabean. With the help of the dwr utility package we can easily fill these spans with data obtain via dwr. This is done with the following to functions.&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
function handleAddClick() {&lt;br /&gt;
   var searchString = DWRUtil.getValue(&#039;searchPostalCode&#039;);&lt;br /&gt;
   AddressServiceFacade.findAddressByPostalCode(fillAddress,searchString);&lt;br /&gt;
}&lt;br /&gt;
function fillAddress(anAddress) {&lt;br /&gt;
   formAddress = anAddress;&lt;br /&gt;
   DWRUtil.setValues(anAddress);&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
The handleAddClick button receives the onClick event from the search button. First we obtain the value from the input field, then we call the dwr javascript object. This method obtains 2 parameters, one more than the real method. The extra parameter is the callback function. This function gets called with the return value of the original java function. We configured the fillAddress function to be the callback function. The special util function &quot;DWRUtil.setValues&quot; sets the values of the address to the spans. The end result looks like this:&lt;br /&gt;
&lt;img width=&#039;400&#039; height=&#039;294&#039; style=&quot;border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://www.gridshore.nl/blog/uploads/ajaxdwrsample_filladdress.gif&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
Download the sources here : &lt;a href=&quot;http://www.gridshore.nl/blog/uploads/ajaxdwrsample.zip&quot; title=&quot;ajaxdwrsample.zip&quot; target=&quot;_blank&quot;&gt;ajaxdwrsample.zip&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
That&#039;s it, hope you like this article. Thanks again to Bram Smeets for his autocomplete component and of course the excellent dwr and script.aculo.us frameworks. 
    </content:encoded>

    <pubDate>Wed, 02 Aug 2006 23:05:01 +0200</pubDate>
    <guid isPermaLink="false">http://www.gridshore.nl/blog/index.php?/archives/52-guid.html</guid>
    
</item>

</channel>
</rss>