This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: ajaxify dependant selection lists with DWR
Feed Title: Logemann Blog
Feed URL: http://www.logemann.org/blojsom/blog/default/?flavor=rss2
Feed Description: Marc's thoughts on Java and more
I am using DWR in a very simple way since one year or something. Back then i created my own Spring creator because the one which was available wasnt very well implemented, or there was no creator altogether, dont know anymore. A few weeks after my implementation, Bram Smeets created also a nice one and put it into the DWR distribution. So today i upgraded to the latest 1.x DWR release and dropped my creator in favor of the included one.
The task was to have dependant selection lists (means, combo2 content is depentant on the value of combo1) without reloading the browser. It was nice to see that DWR is still the ultimate tool when it comes to simple solutions for everyday ajax tasks. Since all the bootstrapping stuff was done a year ago in our app, i only had to change the DTD delcaration of dwr.xml because my was very old. Putting the spring bean creator was an easy task and without any hassle, i had all my spring beans/services available for javascript remoting.
The rest was easy as well, putting 2 javascript functions in my HTML code and use the util.js addOption() function to append new values to my second combo based on the selected value of combo1. Very neat is that addOption() is also capable of working with an MyObject Array where you can also pass the names of the attributes which should act as the HTML select key and HTML select value part. The best of all: On java side i already had such a service for other tasks so i was able to simply reuse (i like this word) my spring service and was finished before i really started.
Sorry that i dont offer any technical details here. I just dont have the time since its 0:40 am here and i want to go to bed now :) Perhaps i will blog later on the details. Bottom line: i am still amazed by DWR and how it plays well with Spring and its really neat javascript helper libs.