Easy(ier) Ajax with Struts 2

Some time back , I wrote an article for Java.net about How to add Ajax to your Struts Application. It’s pretty straightfoward (as is Ajax underneath all the hype), but it still involves too much JavaScript for my liking. Nothing against JavaScript, but if you write it , you have to support it. Far better to use a standard Ajax library , like DWR , Prototype or Dojo.

(As a reality check , if you don’t know what Ajax is , this article explains what Ajax is and what it can do)
Struts 2 Logo

Along comes Struts 2 (. Be careful – it’s good , but very different from Struts 1 – it should have been called WebWork 3). It does a lot of things better – for example , the way it’s Actions are normal POJO’s makes it a lot of things easier to unit test.

Struts 2 also gives you Ajax ‘out of the box’. No writing of javascript, no debugging against various browsers; just configure and go. A full description of how to setup Struts 2 to use Ajax is in this wiki article. The quick version is:

  1. Setup Struts 2
  2. Add the Struts-Ajax URL and Div Tag.

That’s it. Ajax without the fuss.

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s