Choosing a Java Web Framework (Revisited)

Posted by rob on September 18, 2008

About eighteen months ago, I published the following article on this web site. To this day it still remains the single most read article that I have published. I am currently in the process of selecting a Java web framework for a project I am working on, so I thought it would be interesting to revisit the process again. In the upcoming weeks I plan to write one or more articles on ideas related to this activity.

————————

Choosing a Java Web framework for your project is not getting any easier. With the GA release of Struts2 this week, its seems like the Java Web framework comparison is back in play. Here are some things I think about when choosing a Java Web framework.

  • Is it action based? Action based frameworks generally map actions (defined in an HTML form or URL) to code in the controller tier of the application. Action based frameworks are the most popular type of framework. Most developers have had at least some exposure to these kinds of frameworks. The most popular Java Web framework, Struts, is an action based framework. Examples: Struts, Struts2 (based on WebWork), Spring MVC, Stripes, Ruby on Rails (requires JRuby to run in Java), Grails
  • Is it component based? Component based frameworks create a component abstraction in the view tier. Event listeners capture user actions and map back to code in the controller tier. I am of the opinion that component based framework have a steeper learning curve than action based frameworks. Some will counter that component based frameworks offer greater productivity, once the framework is learned. Programming in a component based framework can sometimes feel like programming Java Swing components. Examples: JavaServer Faces (JSF) implementations (MyFaces, Tapestry, RIFE, Wicket, Google Web Toolkit (GWT), ThinWire, Echo2, IceFaces (JSF implementation), Click
  • Is it page based? Page based frameworks allow you to develop application made of many Web pages. To implement these Web pages, the developer creates HTML (using JSPs or templates), JavaScript and CSS files. All action based frameworks (that I know of) and some component based frameworks are page based. Most of these frameworks now have good support for AJAX. Because you write the Web tier yourself, you also have a lot of control and the ability to adhere to Web standards. Struts is a page based framework. Examples: Struts, Struts2/WebWork, Spring MVC, Stripes, Ruby on Rails (requires JRuby to run in Java), Grails, RIFE, JavaServer Faces (JSF) implementations (MyFaces), Tapestry, RIFE, Wicket
  • Is the Web tier generated? New AJAX frameworks such as Google Web Toolkit, require you to only code in Java. They then generate the entire Web tier for you, so you don’t have to code the HTML, JavaScript or CSS. You will still need to understand CSS concepts in order to style you components. This may be attractive you if you or your team doesn’t have much experience with JavaScript and CSS or you want to keep all of you application logic within Java code. These frameworks are component based and the style of programming is very similar to Swing. AJAX is used heavily by these framework to create a rich user interface. In traditional frameworks, there are many Web pages that work together to form an application. These frameworks may only have one page (a frame) where components and screens are swapped out using AJAX. Examples: Google Web Toolkit (GWT), ThinWire, Echo2, IceFaces (JSF implementation)
  • Is it JSP based? Many frameworks, including Struts, use JSP pages to generate HTML. JSP (JavaServer Pages) are the classic way to generate Web pages in Java. Tag libraries are used within JSP pages to generate HTML. Custom tags can be created fairly easily to add your own functionality. JSP pages get compiled into Java Servlets. Examples: Struts, Struts2/WebWork, Spring MVC, JavaServer Faces (JSF) implementations (MyFaces), Click
  • Is it template based? Some frameworks offer an alternative to JSP pages known as a template. Sometimes a framework only works with templates, while there are also lightweight template libraries, such as Velocity or FreeMarker, that can be used in combination with JSP frameworks. A template is often an HTML file with references to Java components made within the HTML code. Because these files are not JSP pages, they bypass the JSP API which many developers do not like to use. This also give some templates the ability to be viewed by a browser, which makes them nice for Web designers. I list some examples of frameworks that use template out of the box. However, as I mentioned earlier, JSP based frameworks can be made to work with templating technologies. Examples: Facelets (a view handler that can be used with any JSF implementation), Tapestry, RIFE, Wicket, Velocity, Clay (part of Shale), FreeMarker
  • Is it Rails like? The hugely popular Ruby on Rails (RoR) framework has defined its own class of Web framework. Without going into the framework itself, two fundamentals of this framework are “convention over configuration” and “don’t repeat yourself”. Rails like frameworks generate a lot of the application structure up front to make it easy to get up and running. Examples: Ruby on Rails (requires JRuby to run in Java), Grails, Trails
  • Does it support a dynamic scripting language? Many frameworks now have support for dynamic scripting frameworks. If you would rather do most of your Web programming in a scripting language rather than Java (there are many who would), then one of these frameworks might be for you. They tend to be action and page based and have good support for AJAX. Examples: Ruby on Rails (requires JRuby to run in Java), Grails (using Groovy scripting language)
  • Does it support IoC? You will often hear this referred to as “Spring integration”. The Spring Framework is a full stack J2EE application framework. There are many different sub-frameworks within the Spring Framework, and its Spring IoC (inversion of control or dependency injection) framework is its most widely used. IoC frameworks can make it easy to configure Java beans within your application, as well as provide a number of other benefits. Most of the popular frameworks have support in one way or another for Spring IoC. If this is important to you, then you should make sure the framework you are selecting makes it easy to work with Spring IoC. There are other IoC frameworks out there, such as HiveMind and Plexus, but Spring is currently the standard.
  • Does it support Web conversations? Supporting Web conversations is about tracking state across several pages, so if you are using a framework that is page based, then this may be important to you. If it is, then JBoss Seam and Spring Web Flow are frameworks to consider. They are not Web frameworks, but server side frameworks that integrate into the middle tier of your application. Seam uses JSF for its Web tier. Spring Web Flow can integrate with various Web frameworks. Shale, a framework for JSF, also includes support for conversations, as well as RIFE.
  • Is it testable? Many of the popular frameworks are building in formal support for mock objects and other testing concerns. Testing is critical and Web applications tend to be difficult to test.
  • How well does it support security? Is it well supported and maintained? Is it stable? Will it help me adhere to standards? These are things I think about on all projects when selecting a framework and they apply here as well. Especially here, since there are so many Java Web frameworks to choose from and new ones are showing up each month.

Matt Raible has done some excellent work in the area of Java Web framework comparisons. He is going to present an updated comparison comparing Struts/Struts2, Tapestry, Wicket, MyFaces (JSF), Spring MVC and Stripes at the upcoming ApacheCon in Europe.

I have only listed some of the most well known frameworks in this article. There are many more available, and too many to list all of them here. If I left out a framework that you feel strongly about, please leave a comment and let us all know about it. If there are additional things you think about when choosing a Java Web framework, let us know those as well.



Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. robbiecheng Fri, 19 Sep 2008 17:35:13 MDT

    Here is another Java, Server-centric framework, ZK.

    ZK is Ajax Java framework without JavaScript. With direct RIA, 200+ Ajax components and markup languages, developing Ajax/RIA as simple as desktop apps and HTML/XUL pages. Support JSF/JSP/JavaEE/Hibernate/.., and Ajax script in Java/Ruby/Groovy/Python/..

  2. Jose Maria Arranz Fri, 17 Oct 2008 09:50:48 MDT

    Very nice classification really. Some time ago I wrote something similar:

    http://www.theserverside.com/news/thread.tss?thread_id=47824#243768

    Steal any idea you like for your “feature list”.

    This is the categorization of ItsNat

    http://www.itsnat.org

    the framework I’m working on (to fully understand my explanations read before the introduction to the framework on the web page).

    * Is it action based?

    Yes and No. Page based navigation is not the focus, you can build the classic page based application but ItsNat doesn’t provide very much, the focus is AJAX. Anyway ItsNat introduces a new technique named “referrers”, the previous page is accessible to the next page, the new page can steal markup and data from the previous reducing the data hold in the client.

    As ItsNat doesn’t impose a concrete servlet I think ItsNat can be plug into Struts or similar and ItsNat template rendering can be used as the view technology.

    * Is it component based?

    Yes, reusing Swing data and listeners models as possible. Components are highly customizable and new components can be built very easily. Anyway you can live without components, they are optional.

    * Is it page based?

    As said before you can do page navigation but the focus is pure AJAX: the application running in the same page with no reload.

    * Is the Web tier generated?

    Yes, ItsNat is server-centric and no client code is necessary, but isn’t “markup intrusive” because the markup is highly controlled by the developer so JavaScript can be mixed with some care including DHTML. Anyway ItsNat provides a bridge to call the server code from custom JavaScript code received as special DOM events in the server (user events).

    * Is it JSP based?

    No, ItsNat has an alternative templating technique. I just use a starter JSP to launch the app server and the browser :) ItsNat in no way depends on JSP.

    * Is it template based?

    Yes. ItsNat templates are *absolute* pure HTML (and SVG) pages with absolutely no logic (this view logic is done using Java W3C APIs). Furethermore “fragments” are pure HTML/SVG too, fragments are pieces of markup that can be included into the main page when needed.

    * Is it Rails like?

    No, ItsNat promotes best practices: static view separated of the view logic and business logic and persistency logic.

    * Does it support a dynamic scripting language?

    Yes and No. ItsNat is developed in Java and the focus is Java, but user code can be coded in a JVM scripting language.

    * Does it support IoC?

    ItsNat approach is “classic”, that is, imperative, as you say an IoC container can be used to manage user code.

    * Does it support Web conversations?

    Web conversations have sense in page based navigation. In a single page/pure AJAX application there is no need to share data between pages (in fact the session object is not needed anymore).

    * Is it testable?

    Yes, functional testing is built-in. ItsNat AJAX applications can be functionally tested simulating user actions using a technique called “server-sent events”, basically W3C DOM events are fired from server and sent to the client simulating user actions. The advantage is: testing code and normal code/data are together, testing code can see server data to check if the task was done correctly.

    * How well does it support security?

    Security is a primary concern, the server-centric nature helps very much.

    * Is it well supported and maintained?

    ItsNat is open source but it isn’t a free time-pet project, is business driven and professional open source.

    The learning curve is very very flat, you won’t need very much support.

    * Is it stable?

    ItsNat is pre v1.0 but API is becoming stable. An ItsNat applications is mainly coded using Java W3C APIs and pure HTML/SVG code this prevents any ItsNat specific API change doesn’t impact very much your application.

    * Will it help me adhere to standards?

    As said before your code is basically Java W3C APIs and pure HTML/SVG code, aren’t they standards?

    Regards
    Jose Maria Arranz

  3. Jose Maria Arranz Fri, 17 Oct 2008 10:01:57 MDT

    I forget to say that for me “beta” != “with bugs”
    For me “beta” = missing some features and API may change.

    I’m not saying ItsNat hasn’t bugs, it may have, but they aren’t identified.

Comments