Friday, February 13, 2009

Web frameworks and Ajax

What I wanted to share today are some criteria that you might want to look at when looking at using Ajax components (Extjs, Dojo) and Web Frameworks like Spring, Struts.

How we decide on the Ajax component/framework the first time round?

Simple ... we just looked for the best and sexiest one around ... and we settled on Extjs. Seems to offer all the componets we wanted.

So we tried putting Spring MVC and Extjs to work together.

After starting to program...

After programming for about 2 months, we found somethings that you probably should try with each of the frameworks before you decide.

1. Submitting forms

Find out how the ajax library submits forms, for example Extjs submits forms using the "ajax" way, and expects the reply as a JSON string indicating success or failure, while Spring does it the traditional way that is through GET/POST and you are also able send Java objects and get back Java objects. So when you merge these 2, you need to either make Extjs send as a normal post/make Spring send back spcific JSON strings.

We went for the first approach, so we were unable to get Spring's simple form controller to get back objects so we just use the normal HttpServletRequest object to read the ParameterMap and form objects from the map.

Take note also that not all components can be sent back as a Post response. Things like Grids in Extjs can't be sent back automatically so we had to use hidden fields and set them to the Grids data (in JSON) to send back to the controller.

2. UI Components

Things that looked good in demos,  is sometimes  not too easy to replicate and to decipher, our first approach was to try and modify similar layouts to our needs but then we found out that most of the demo code resides in javascript files and  not embedded that made debugging abit harder for us. And the code was getting messy with comments here and there and debugging was painful.

So we did a bottom up approach where we slowly tried to learn and build the UI and we embedded most of the UI code in the jsp page itself and used firebug extensively to debug. It took a lot more time but hey we understand how things work better.

3. Cross Platform

The main use of such Ajax frameworks over coding your own is most of them cater for cross browser compatibility but its still up to you to fully test your website.

We found Firefox to be more forgiving in terms of certain mistakes where in IE that page won't even be rendered. Things like additional commas when defining array and missing variables are more likely tolerated in Firefox than in IE.  So test at least on IE and on FireFox and on as many browsers you can get, u maybe surprise at the errors that you get.

No comments:

Post a Comment