JQuery…my new favorite Ajax framework

After a several stints with Dojo, Ext and Prototype, I decided to see if JQuery could provide anything better. I figure it’s a good thing to be versed in several Ajax frameworks. You never know which one you might use next really. I am definitely weary of Dojo and it’s lack of support and constant revamping to remove things that worked previously. I love Ext, but turning around and charging for it was really a bad idea on their part. I think they have the best forums and support and their API is really easy to use.
After looking into JQuery, I was pleasantly surprised to find out how lightweight it was. It is a tiny fraction of the size of the Dojo library and the syntax of use is more concise and direct. Of course, this lack of size is mainly because all of the widgeting control is included in other separate plugins that you can add on, but I do like that. It is simple to download a plugin or write your own. I really avoid writing something custom unless a last resort. There is always one out there ready for use.
So, I put JQuery into my project and I already had a Spring Controller using Content negotiation serving up my JSON and I gave it a whirl. It just a few minutes I was able to get data from the JSON object and then populate anything or do anything I wanted to do with it. I accomplished it in just a few lines of code.


$.getJSON(“rest/DataService/loanTypes.json”,{id: $(this).val(), ajax: ‘true’}, function(j){

var options = ”;
var loanTypes = j.loanTypeList;

var currOptions = $(“select#loanTypes”).html(options);

for (var i = 0; i < loanTypes.length; i++) { options += '’ + loanTypes[i].loanType + ”;




At first the $ notation takes a little getting used to, but just think of it as a dojo.byId on steroids. It’s a really powerful notation. This is just a snippet from the example, but I just get the JSON from the server and populate a select box manually creating option elements. Ordinarily I would frown upon doing this, but it’s just an example. A proper way would be to use a JQuery UI component that would just take the JSON automatically.

I found several plugins that were really useful on the JQuery site. I even used JQuery UI and another plugin to replace alert messages with Ajax Alerts.

Most of the other libraries out there are all very self contained, but JQuery just allows you to download plugins at will. This is very powerful but it has it’s drawbacks. You have to make sure that the plugin you download and all it’s dependencies all match with the supported versions of each. This can make upgrading JQuery difficult if you use a lot of plugins. I recommend using them cautiously.

You can find a list of all the JQuery plugins here.


You can download and install JQuery into your project as simply as downloading the js file and including in your HTML page.

Go get it and try it out.

JQuery http://www.jquery.com

If you want support or see other examples of how other users are leveraging the framework, check out the forum.


Make your Web Services simple with Apache CXF and Spring

Have you ever just wanted to make Java Web Services so easy that you can whip one out in a few minutes, well here is your shot. Apache CXF and Spring make creating a Web Service almost stupid simple. I’ll get right to it.

First you need to configure CXF in your web application by adding a few lines to the web.xml.




All this is doing is setting it up so that all requests for /ws/* to get routed to CXF. Now we need to include a new xml file for Spring to load.

<beans xmlns="http://www.springframework.org/schema/beans&quot;

<bean id="aegisBean"

<bean id="jaxws-and-aegis-service-factory"

<jaxws:endpoint id="applicationWebService"

Now, we are ready to write our service class. I typically create service classes to interact with my other backend services, databases, web services, etc. Here is an example.

@WebService(endpointInterface = “com.domain.services.IApplicationService”, name = “applicationService”, serviceName = “applicationService”, portName = “applicationPort”, targetNamespace = “http://services.domain.com/&#8221;)
public class ApplicationServiceImpl extends ServiceImpl implements
IApplicationService {

public String sayHello(){

return “Hello”;

And that is pretty much it. Start up your Web server and hit /ws/applicationService?wsdl and you should get a WSDL for the service automatically generated. You can use SoapUI as a testing tool to test out the services. You can also use SoapUI to generate any type of client that you want for the services, JAX-WS, JAX-RPC, Axis, you name it.

It doesn’t get much easier than that does it? I’ve only scratched the surface of CXF as well. It has many more features.

Spring and CXF make a truly versatile way to create an SOA architecture or an Enterprise Service Bus all on your own as well.

Caching Java methods with Spring 3

A while back I wrote about caching Java methods using an earlier version of Spring, but now I am pleased to announce that you can cache your methods using annotations with Spring 3 using Ehcache annotations for Spring.

Similar to my other post you can cache a Java method in a Spring bean by simply adding the annotation.

public Collection getDogs() throws Exception {

I really put this annotation to work in my latest project because I called many Web Services in my code that return very static data that is managed by our Enterprise Service Bus. There isn’t any need to go get the data every time since it hardly ever changes.

Using the annotation, I specify that the cache region I want to use is dogCache from the ehcache.xml file and I have it configured specific to have it handle caching dogs exactly like I want it to, even to overflow to disk if necessary. Now let’s look at the configuration necessary.

You will need to drip the jar file for ehcache-annotations in your WEB-INF/lib and then make the following modifications to your applicationContext.xml.


And that’s it, you are now caching your results. Be very cautious with using this, each and every method that gets cached must be thoroughly thought through. For example, I accidentally placed this annotation on a method that returned domain objects that were already configured to be cached via Hibernate, thus doubling the amount of memory that the server was using for each object loaded.

While a very powerful tool that can increase performance, caching can also decrease it.