October 29, 2007

Java Server Faces are Weak

I'm very familiar with Struts and I like it a lot as a MVC framework for developing web applications. However, it's a little heavyweight, because it supports a lot and makes it possible to do many different things. Perhaps it would be easier to use something lighter for smaller web applications, like JSF in conjunction with the JSTL. As it turns out, JSF is pretty weak and doesn't even work with JSTL because there is no way for the tags to reference the information owned by the other.

JSF can be used to build HTML forms that are backed by beans. So you can use tags to create a form that will populate a bean, and likewise use a bean to populate a form. Beans can also be used to display data on the page, in general. You define the beans and their default values in a single configuration file that shared by all your pages. The navigational path between pages is also defined in a single configuration file, allowing for branching and looped paths. You can propagate beans between pages to carry information forward, and by putting logic into a bean's getters, some pure Java code as well. There is also support for some basic validators as well as custom validators, and display of errors that fail validation. Proponents of JSF argue its strengths as a MVC framework (see JSF for Nonbelievers).

However, there are some problems with JSF that I simply could not overcome. Perhaps the biggest of which is the inability to mix JSF tags with JSTL tags. JSF has a limited set of tags, not all of which provide the functionality I desire for more complex HTML generation. JSTL adds some of the tags I want (although it is not as full featured as the ones provided by Struts) but there was no way for me to reference the JSF beans directly from JSTL, to perform manipulations and iterate over values. I can shove JSF values into JSTL tag attributes, but I could not actually get a handle to the real bean object itself.

Another problem is how forms are programatically constructed using JSF tags. The form elements are given generated IDs which you have no visibility into. They tend to look like id0_id1, and are only generated at runtime. As a result, there is no way for me to reference those elements using client-side JavaScript.

Also, if you look at how the JSF MVC architecture is described by Richard Hightower, you'll notice there is not actually a clear separation between the model and controller. If there was, you would not need to reference the controller or its business logic from the model. Some might argue that's not so different from a controller that is referencing the model and its data, but the JSF approach is backwards because it prevents code reuse. In other MVC approaches, I can use the same model in many different controllers, where the data is the same but the business logic is different. In the same way I can use the same model in many different views, to change how I want to present the information.

All of the problems I've described do not exist in Struts. I am not familiar with the Spring Framework though, which is supposed to be a very good alternative to Struts. The documentation on Spring that I have looked at seemed to require thinking about things from a different perspective, but if you do so then you have a very powerful tool. There's also Stripes, which I have only taken a very brief look at. From the Quick Start Guide, it seems like Stripes specifically merges the model and controller into one class on purpose, to make things easier on the developer. But that creates the same reuse problem I described above with JSF.

Posted by josuah at October 29, 2007 6:09 PM UTC+00:00

Trackback Pings

TrackBack URL for this entry:
http://www.wesman.net/cgi-bin/mt/mt-tb.cgi/1363

Comments

Post a comment

July 2013
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search