Choosing a Java Web Framework
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.
ICEfaces provides a very easy way to make Ajax applications with the standard JSF components (as well as the custom ICEfaces components). It also supports Ajax Push, which makes it possible to update the page from the server independently of user interaction. ICEfaces works well with Seam and Facelets.
Small correction: Spring MVC makes it a trivial to use alternate view/templating technologies other than JSP. In fact, a project I am working on uses Freemarker.
I added IceFaces and FreeMarker to the list. I also made an additional note that about using templating technologies instead of JSPs in some frameworks. Thanks for the comments.
Excellent summary of framework taxonomies!
A couple of notes:
* Struts 2 supports using JSF components as a view (via an optional plugin).
* The Struts 2 tags fully support Velocity and FreeMarker, and in fact the tags are created using FreeMarker templates.
* Struts 1 supports writing Actions in any Bean Scripting Framework language. (I’m sure this could also be done for Struts 2 if there was any interest.) There’s also been a lot of work on Groovy actions for Struts 2 lately.
-Ted.
Nice break-down of evaluation points. You can also think of adding:
- does it require Java 1.5 / Annotations?
- does it have good support for Ajax?
- does it have a lot of dependencies on other frameworks / languages / scripting or templating languages?
- does it have good IDE support / plugins (preferably open source)?
- how much does it cleanly separate your web/HTML design team from the Java dev team?
I have touched upon some of these aspects in this blog post about Wicket where I have tried to draw some comparisons with other frameworks.
http://ptrthomas.wordpress.com/2007/03/02/wicket-impressions-moving-from-spring-mvc-webflow/
A small, but important correction:
“Examples: JavaServer Faces (JSF) implementations (MyFaces, Facelets)…”
Facelets is *not* a JSF implementation. It’s an alternate ViewHandler implementation that can be used with any JSF implementation. The current JSF implementations are, for the 1.2 spec, the RI (http://javaserverfaces.dev.java.net), and, for the 1.1 spec, the RI and the aforementioned MyFaces.
I like this list a lot for choosing something new if you don’t already have an investment, but how about “What are you using now?” Many shops already have expertise in whatever they have used before and while that alone isn’t justification to stay where you are, that it certainly influences what choices you realistically have.
How easy is it to learn Platform X given you already know Platform Y?
Is it a complete rewrite or do you get to migrate code easily?
I’m sure there are others, but you get the idea.
—Pete
http://nerdguru.net
Pete,
I think my article or others like it can be used to decide on Platform X, given you already know Platform Y. Of all the items I listed, I think the decision to go action based vs component based is one of the biggest and is why I listed those two items at the top of my list. If you have a team with Struts experience, then Struts2, Spring MVC, Stripes and Grails may all be good choices as they are all “action based”. However, there are so many factors in play, so I don’t think I would make my entire decision on that alone.
I don’t think there is any definitive answer to what is the best path. JSF is a also a valid path, and many like the fact that it is a J2EE standard. This hopefully will allow you to learn one API and work with multiple implementations such as MyFaces or IceFaces.
I have seen some articles on migrating from Struts to Struts2, but I don’t have the experience to give you a good answer on how much of the migration is a rewrite.
InfoQ did a series on migrating Struts to Struts2 that can be found here:
http://www.infoq.com/articles/converting-struts-2-part1;jsessionid=A1141C613A5DC87B6D01899EF01C2CA3
Jason,
I appreciate the feedback and have fixed the article.
Excellent work, specially categorizing the different kinds of frameworks. There are little works on the Internet as clear as yours.
I recommend that you can put it in a wiki where others can contribute.
Please also include Click which is jsp and mvc free.
Regards,
[...] An interesting take on categorizing popular web frameworks - I’d love to see this represented graphically - Tufte disciples - get crackin’! [...]
Hello.
Got an article that describes some of the time saving techniques with Spring MVC.
http://coderslog.com/Convention_over_Configuration_for_Spring_MVC
The site itself is a free non-profit resource for java developers working on large-scale projects.
[...] Please help me here to use existent categories. [...]
[...] 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. [...]
Vergleich Webframeworks…
Webframeworks gibt es wie Sand am Meer. Die nachfolgenden Links beschäftigen sich mit dem Vergleich der üblichen Webframeworks. Diese Links beschäftigen sich hauptsächlich mit dem Vergleich von Spring(Web)MVC und JSF: Comparing Webframeworks,……
[...] I didn’t want this article to be another taxonomy of Java web frameworks like my original article. Instead, I wanted this article to present a pragmatic way to select a framework that is easy and [...]