JavaServer Faces vs. Ajax Frameworks - Why Ajax is Better and Not Just Hype
I'm not advocating Struts either as a solution mind you. I worked on Struts projects for years and enjoyed them. It was the best Web framework at the time, which was several years ago now. If you're starting a new project, save yourself some time and don't choose Struts, and for God's sake, stay away from JSF.
These days I prefer to use an Ajax frameworks like Dojo, Ext, Scriptaculous, JQuery..etc, to build my presentation tier. Most developers will say the same thing about these frameworks I say about JSF, it is all hype, confusing and doesn't perform well. In order to respond to these claims, I am going to justify my preference for these frameworks in just a few simple sentences. Feel free to start a debate with me if you don't like my stance on JSF, but after 4 years of on and off dealing with it, I'm sure you can't say anything that will change my mind.
Reasons to use an Ajax Framework over JSF
- Ajax promotes a clear separation between your page technology and your server-side technology. My applications can use anything on the backend, Spring/Hibernate, .Net, Python, PHP, Perl, Ruby...you name it. This is because I only transport JSON data to and from the server. No JSP, JSF, ASP or any of that sort.
- Clear separation of roles. In a larger shop, you can have Java developers and Ajax developers. They don't have to bridge the gap between each other's jobs unless they want to. They only need to understand JSON, which is easy and much lighter than XML.
- You don't have to worry about writing one language with another. Remember in the servlet days when we wrote HTML with Java, in JSP there was often scriptlet code intermingled with HTML, much like in PHP and ASP. My Ajax code only contains components from the libraries I am working with and I have never had a problem with two of them clashing. JSF is a disaster when it comes to components playing nice on the same page, especially when they are Ajax components.
- I have finer grain control over the look and feel of my application. Dojo and Ext widgets are very customizable, much moreso than primitive looking JSF components. Sure, you can write your own JSF components, but I'd rather used a canned Ajax one that works better.
- The Ajax framework components are extremely rich. In Ext, I have a grid that sorts, searches, filters and all that and a bag of chips. In JSF, I couldn't get half of that functionality, and a majority of the time, operations happen on the server and the page refreshes.I don't want to reload the entire page...just the data.
- Ajax components and refreshing the page results in a repainting of redundant data. With an Ajax framework, most of the time, you build a component and only interchange the data using JSON. Why do I want to continuously refresh a page or section of a page to repaint the component, when in Ajax the component is ready and just needs data.
- I can test without having the application server running. If I want to test a piece of code or a snippet, I don't have to wait until it is deployed. I have browser right there to try it out.
- I can asynchronously load several components at one time. Let me see you add 3 grids to a JSF page and update all three grids at different times. Here is a little tip, you'll jump through hoops making it work and you'll more than likely refresh your page 3 times and it will perform like poo. With Ajax, I refresh all 3 grids at the same time and the page will never flash. Matter of fact, the first one will load and give the user some data to look at while the second one is loading it's data.
- I generally avoid statements like "it's really cool", when referring to a framework, but in this case it fits. For example, last night I wanted a login form to appear on a page that is asynchronously loading and times out. The backend server was whacked and the page continued to load data, getting login problems when the server came back up, the login form appeared over the top of the screen, I logged in and the page was as it was when the server went down and I never left the screen. The only data that was exchanged, was the actual data the page needed for display. No unecessary HTML being transported over the wire.
If I haven't convinced you that Ajax frameworks are better than JSF, let me know and I will make sure you get to write JSF on a project for a few months and we'll see how you feel afterward. If you still don't agree with me, I'll buy you lunch.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)