Syndicate This Blog
Thursday, August 31. 2006
I have created a lot of small applications that include spring and acegi. Most of the time I copy most of the resources from another project. Some time ago I learned about the maven archetypes. An easy way to create the project structure. That was the time I decided that I wanted to have my acegi springframework archetype. Last weeks I found some time to create this archetype. You can download the files here:
And the generated maven site here:
Ofcourse there is also a maven website about creating an archetype, this is not a very extensive website. In this blog item I will explain more about the archetype I created.
First thing to know, well surprise, the archetype is just a maven project. You can start you new archetype by using a maven archetype:
Have a look at the pom for the other properties; scm, distributionManagement, etc.
The project itself contains an src\main\resources\META-INF\maven\archetype.xml file that defines all the resources that need to be copied.
The structure is pretty easy, you can find all the resources under the directory:
You can use the following parameters in your file as placeholders:
http://maven.apache.org/plugins/maven-archetype-plugin/create-mojo.html. Have a look at the src\main\resources\archetype-resources\pom.xml for an example:
Hope that helps you on your way to your own archetype. If you just want to use mine:
Friday, August 25. 2006
Yesterday I attended the Profict Java Summer Camp. And what a camp it was. The first surprise was the location, what a nice environment to do your work. In introduction of profict, "we are hiring". Then the real camp started. 4 hours head on with Greg Murray. Greg is working for more then 10 years with java, mostly for sun. The last years he has been busy with AJAX. He gave a very enthousiastic talk about a ajax and some frameworks. Just to give you some pointers:
Dojo framework, jMaki frameowork, ajax blueprints, netbeans.
He showed a lot of examples, a few I liked very much.
http://www.isoma.net/games/goggles.html (Oops not ajax)
In Brief, a very nice presentation with a lot of information. It could have been a little bit shorter. Some nice pointers to start new research into java
The next presentation was by Bram Smeets of interface21. We allready know him, read one of the other posts about dwr on my blog. He gave a very good introduction to the powers of dwr and what it can do if you combine it with spring. I guess I allready knew, still, it was interesting to see and hear Bram talk about it and put some stuff into perspective. I am curious about the next step of dwr and the use of spring 2 stuff within DWR.
After the presentations there was a nice barbeque, had some good conversations with Greg, Bram and others. It was a very nice camp, thank you profict.
Tuesday, August 15. 2006
Last week I started experimenting with google code. What a simple thing it is. Nice to have a svn repository and have some very small project toolset as well. There is an issue list, you can add developers, have some mailings. No to much, but it is working. From now on you can find my sample code in this location:
Have a look, and if you find issues, please report them via the tool.
Wednesday, August 2. 2006
After this rather long introduction, time to get the coding done.
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:
Execute the command to setup your eclipse environment and startup eclipse.
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't it?
We are going to expose a service object with two methods:
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.
Fianlly there is a transferobject called AddressTO that contains the following 4 fields: streetname, houseNumber, city, postalCode. Download the source to have a look.
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
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:
Everything is ready to do the first test. Deploy the application to tomcat and call the following url: http://localhost:8080/ajaxdwrsample/drw
You should get a page with a link to AddressServiceFacade, click this link and have a look at the next page:
test page of dwr
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't it?
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 "scripts". 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 "autocomplete.js" file. Finally the index.jsp that implements the real automcomplete component.
The constructor for the autocomplete component has 4 parameters:
The callback function looks like this:
Doesn'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.
The autocomplete box will now look like the following image:
The id'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.
Download the sources here : ajaxdwrsample.zip
That'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.
(Page 1 of 1, totaling 4 entries)