Ajax programming with Struts 2

Five steps to dynamic tables using Struts 2, Dojo and JSON

Ajax developers know that tables can do a lot more than display static information in an organized, readable format. By syncing up your table rows with a server-side database, you can create dynamic tables that sort, filter and paginate data on the fly. In this article, Sun Certified Java Developer Oleg Mikheev shows you how to use Struts 2, Dojo and JSON to display server-side data in an Ajax-style table. In the process, he introduces some of the Ajax-friendly features of Struts 2, including its integration with WebWork, Guice and the Dojo toolkit.

Almost every Web application incorporates tables, and Ajax-style Web apps are no exception. Tables in Ajax applications can't just display information like they would in any old Web app, however: Ajax implies dynamic filtering, sorting and pagination. There are many solutions for addressing dynamic, tabular functionality on the client side, but this approach doesn't satisfy most project requirements. Dealing with hundreds of records on the client is too complicated a task for even a modern processor. More important, in an Ajax application the data is expected to be always in sync with the current database state.

Several Ajax solutions simplify Ajax programming by converting server-side Java code into JavaScript, but at the cost of flexibility. Most developers don't want to be restricted by the dictated programming model and limited number of components these frameworks provide.

Given the options, creating a custom Ajax table really is your best choice. In this article I propose a custom solution that works and I show you how to implement it using Struts 2. Along the way, you get a quick tour of some of the frameworks within the framework that is Struts 2 -- namely OpenSymphony WebWork/XWork, Guice and Dojo -- and find out how Struts 2 integrates these powerful allies to make Ajax development a pleasure.

If you need an immediate solution to the problem of displaying server-side data in an Ajax application, cut to the quick list. You'll get a five-step solution with code samples you can use today. If you're more generally interested in Ajax development, or want to learn about Ajax support in Struts 2, then read on.

Note that this article assumes you are conceptually familiar with Ajax development. Experience with Struts 2, Dojo and JSON is helpful but not required.

1 2 3 4 5 Page 1