Thinking in Stacks (Revisited)
This is the third of three previously published articles related to Java web frameworks that I am republishing. This one is from about fifteen months ago. Choosing the correct stack of software to support a web framework is important. You can either build your own stack or choose from an already integrated stack.
———————-
The number and diversity of Java frameworks (and web/MVC frameworks in particular) is a great thing. But along with choice also comes drawbacks. Which frameworks do I choose for a new web application? Project X is using frameworks A, B and D - do you know these? Are they production worthy? I have heard for every project you should choose the best tools (or frameworks) for the job. Really? I tend to agree to an extent. But is one Web application so different from the next that I need to reevaluate which frameworks I use on each new project?
This leads me into what I really want to discuss. I believe there has been a positive development in the Java world, in that popular “stacks” of open source software are beginning to emerge for developing web applications. I am defining “stack” as simply “multiple software frameworks integrated and used together”. Wikipedia defines a similar term, solution stack. Should project teams start making stack selections instead of framework selections? While frameworks maybe should ultimately be selected based on their individual merits, I think a popular stack can be a great place to start. Some of the benefits of using a popular stack include: accelerated startup time, reduced learning curve, increased software quality and increased knowledge base. So far, I see three stacks emerging as the most popular.
The first stack is the Spring/Hibernate stack. Maybe this one is the most obvious. Over the last fews years Spring and Hibernate have become so popular that they have almost knocked EJB2 out of existence on new projects and forced the creation of the new EJB3/JPA specification. I think this stack is still maturing, in that projects are adding everything Spring has to offer in addition to the already popular Spring IOC and Spring Transaction frameworks. By that, I mean using Spring MVC for the web tier, Spring Web Flow for work flow and any other Spring frameworks that are found to be useful. Maybe I should simply call this stack the “Spring stack”. It should be noted that the very promising Grails framework is built on top of Spring MVC, Spring IOC/Transaction and Hibernate.
The second stack is the JBoss Seam stack, which is basically a stack by definition. JBoss Seam ties together the JSF framework specification, using MyFaces for its default implementation, to the JPA specification, using Hibernate (another JBoss product) for its default implementation. The JBoss Seam framework itself adds work flow and other capabilities to the middle of the stack. Other JBoss frameworks like JBoss Rules can easily be integrated into the stack. If you like the idea of working with J2EE specifications and tools designed for J2EE specifications, then this stack may be the one for you. A big positive of using JBoss Seam is that it reportedly handles of lot of issues developers encounter when working with JSF.
The final stack is the Ruby on Rails (RoR) stack. JRuby 1.0 has just been released and is expected to execute close to if not 100% of RoR applications on the Java platform. The increasingly popular and much imitated RoR gives you everything you need in one package, with ActiveRecord for persistence along with MVC functionality and much more. If you have ever read or listened to interviews with RoR creator, David Heinemeier-Hannsen, you might recall him talking about why he created RoR as a way to quickly create a new web application without having to start from scratch. David wants RoR to give you everything you need to create a web application right out of the box, with little or no configuration, so you can focus on the business logic and not the underlying framework code. I mentioned that the Grails framework/stack is built on the top of the Spring/Hibernate stack. Grails is a Java implementation of a RoR like framework.
This discussion wouldn’t be complete if I didn’t mention the AppFuse project. Created by Matt Raible, AppFuse let’s you quickly create an application skeleton using various combinations of the most popular Java frameworks. Without going into too much detail, you can choose from four popular Java web frameworks (Struts2, JSF, Spring MVC and Tapestry) and three Java persistence frameworks (Hibernate, iBatis and JPA). Spring is used to tie everything together. I think of AppFuse as being a nice alternative to choosing one of the above stacks, while still getting many of the same benefits.
The downside to the emergence of these popular stacks is there are some great frameworks not included in these stacks and not getting as much attention as a result. A few that come to mind are Struts2, Tapestry, Wicket, Rife, Guice and Google Web Toolkit. While I feel having a small number of popular stacks is a good thing, I also see diversity and innovation as good things. I guess you have to make a choice between what is most important to you, starting with a small group of popular technologies, or selecting from the latest and greatest.
If stacks truly become the way the Java community prefers to view software in the future, I think we’ll start to see the creation of new frameworks slow down and a lot more activity continue around the already popular stacks. In true Java tradition, perhaps there will even be a couple new stacks show up in the next year (Google stack anyone?).
Great Book Titles From DHH
I just watched David Heinemeier Hansson’s keynote from RailsConf 2008. As usual, it was very good and offers a nice perspective for someone who works in the world of Java development.
David referenced several interesting books during his presentation.
- Agile Web Development with Rails - Sam Ruby, Dave Thomas, David Heinemeier Hannson (I would plug myself too)
- The Secrets of Consulting - Gerald M. Weinberg
- My Job Went To India - Chad Fowler
- Implementation Patterns - Kent Beck
- The Innovator’s Dilemma - Clayton M. Christensen
- Envisioning Information - Edward R. Tufte
Web Conversations in Java (Revisited)
In the spirit of selecting a Java web framework, I am going to republish a couple more articles related to the subject that were previously published on this blog. Below is an article I published over a year and half ago related to web conversations in Java. Support for web conversations is an important topic when selecting a Java web framework. If anything its probably even more important today than when the original aricle was published, since the subject is better understood today and by more people.
————————-
Sometimes in a Java Web application you may want to pass data from one screen to the next. A shopping cart is a good example of this. Another is a “wizard”, which leads the user through multiple steps when entering data. You can pass the data from one to screen to next in a stateless or stateful way depending on how you want to design your application.
With shopping carts, if you were to open two of them for the same Web site at the same time, the data entered into one would probably step on the data in the other. I think to most users this is understood and I believe most of us know that opening a shopping cart more than once is a bad thing. However, in a business application, it may actually be desirable for a user to open a wizard more than once at the same time. If this is the case, then multiple instances should not step on each other.
There are many factors to consider when deciding to make a Java Web application stateless or stateful, but I won’t go into those issues here. Its a very complex decision and there are many chapters in many books dedicated to the subject. Let’s assume we want a stateful application. For our wizard screens, using the HTTP session object simply will not do the trick for us. The HTTP session object is generally shared by each instance (window or tab) of a type of browser (Firefox, IE, …). If you have multiple Firefox browser windows open, they will still still share the same HTTP session. Its not entirely consistent on how this works, but to describe this behavior would take too long here and is the subject for another day. What we need is memory that is not shared by each of the wizards. We need data that is scoped to a series of user interactions in the wizards. What I have found is that this concept is starting to be referred to as a “conversation”.
A “conversation” can be thought of as a series of interactions between the user and the Web application. In this discussion our user interaction is taking place in the wizard pages, where the user inputs data and moves from one screen to another in order to complete their data entry. In order for conversations to be properly supported, multiple conversations need to be able to take place at the same time. This would allow us to have multiple wizards open at the same time. I think of conversation scope as being in between session scope and request scope.
There is a Java Web framework that is formally supporting conversations, Seam. In Seam, you actually specify in your Web pages when you want the conversation to begin and end. Seam takes care of the programming on the server side to make it all work. It would be nice if more frameworks would support conversations in this way. I haven’t used Seam yet, but this feature may be a good reason to give it a closer look.
Spring Web Flow is another framework supporting conversations. It is a layer that sits behind a Web framework such as Struts or Spring MVC. Spring Web Flow appears to be very in depth in its support of conversations. Given the popularity of the Spring Framework these days, I would recommend giving
Choosing a Java Web Framework (Revisited)
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.
Stack Overflow Ships
The new Stack Overflow web site finally went live. I won’t go into details about it, because you can get them here. I’m excited about this programming Q&A site, because I use Google and other online resources many times every day to answer technical questions, find code examples or simply take a pulse of what technolgies other developers are using. I really like this site’s social networking take on programming Q&A. I havea strong feeling this site will become a very used tool in my programmer’s toolbox.
You Gotta Love Choice
I really like the new Google Chrome browser. That gives me five browsers to choose from, which I think is great for interoperability. Here is how I rate them personally.
- Firefox - Plugins rock. I also just really like the way this browser is designed.
- Chrome - Very nice considering how new it is. I like the URL bar per tab. Maybe Firefox will think about that feature also.
- Opera - Nice, but not enough for me to switch from Firefox.
- Safari - Like Opera. However, I must admit I have spent much time in it.
- Internet Explorer - When I using IE, I can’t help but feel like I driving a cheap car. Sorry Microsoft.
JEval Eclipses the Century Mark
My open source, Java expression evaluation project, JEval, has now been downloaded 1,100 times in about the last 18 months. Thats nowhere near the numbers the big projects get, but with over 50 downloads per month, I feel pretty good about the level of interest.
Why All the Drug Ads?
My blog got hacked a couple of weeks ago by someone who was inserting hidden Viagra and other assorted drug links into my pages. This was actually brought to my attention by Google, who said they were temporarily removing my blog pages from their indexes until the problem gets fixed. I believe that I have the problem fixed now, but will need to wait a few days to see if the hacker comes back and is able to get around the security I know have in place.
The drugs ads are showing up, because the hacker tricked Google into thinking my site was related to the drugs found in the hidden links. Therefore, Google serves up the drugs ads to match what it thinks is on my site. If I can get a fix in place, I will notify Google to reindex my pages. I figure I will leave the drug ads up in the meantime, because I wouldn’t want to deny any of you the chance to get some great medications over the web. ![]()