As I continue learning the Spring Framework, the more I like it :)
Spring is composed of several modules, and although there is one Core module, which I should have read first, I began with the MVC module (mainly because I was more comfortable with it).
Comparing the Spring MVC with Struts (which I have already worked with), I find the Spring MVC more flexible and powerful. For example, when we develop a Struts application we normally worry with Actions and ActionForms. Actions are the entry point of any request made to the application, and ActionForms are specialized beans for encapsulating request parameters. And every "functionality" of the application must have one of these.
Spring has a more pragmatic approach. You don't need to have an ActionForm (called Command in Spring) per Action (called Controller in Spring) if you don't want to. There are plenty Controllers from which you can extend, that provide functionality for a variety of situations (multi actions in one class,
simple forms support, wizard-like interfaces, etc).
Another big difference is the Command Class (ActionForm). It can be any POJO (Plain Old Java Object). No need to subclass anything. This way, if you want, you can use your Model Beans along with their property types. The properties can have, in theory, any type you want, as Spring can already handle a large amount of common types (for the others you need to provide your conversion mechanism).
Another great addition is Handler Interceptors. Basically, you can define a chain of classes that "intercept" the call to any Controller, to do some pre-processing and/or post-processing (very useful for authentication issues for example).
There are other differences, mainly to inject some flexibility to the process: you can choose between different ways of deciding which Controller is called, which View is used, etc.
Despite all this, Spring still has at least one shortcoming: documentation. This is a recurrent issue in open source projects. However I feel that a lot of effort is being done to overcome this (the reference manual is very well written, albeit still incomplete). For example, I couldn't find any reference in the web that explained how to use the AbstractWizardFormController (Controller responsible for the wizard-like interface). I hope to post here a small tutorial for it after I'm finished with some experiments...and if in the meantime nobody else writes one ;)
Wednesday, September 29, 2004
Spring MVC versus Struts
Tuesday, September 21, 2004
MVC frameworks
I've been using Struts MVC framework for a while. It's a solid and very popular framework. So popular that sometimes we forget to check what else is there... In my little research I came across with two very different frameworks: WebWork and the Spring Framework.
WebWork seems to have an aproach very similar to Struts. However, it feels like an improved Struts (no more ActionForm's :) ). However, I didn't analyse it too deeply, so I can't tell all the advantages/disadvantages.
To be true I gave much more attention to our second contestant: the Spring Framework. This one is quite different. It's much more than MVC (MVC is just one of the modules). In fact, you can use WebWork or Struts along with Spring...flexibility is the key :)
I'm doing some experiments with it....I'll post some of the things that I find in here.