Struts and WebArch

The Apache Struts Web Application Framework

At first I thought this post wouldn't fit this blog's theme, but then again, I realized it's all about Web Architecture.

I've been using Struts for years, and it's a true love/hate relationship. Actually, it's more of a Like/Hate.

I'm going to try to enumerate why I like it, and why I don't.

Why I like it:

  • Automatic form validation. In retrospect, I only use this sometimes. Still, it's nice to have a form fail validation and get redirected to the input page.

  • Automatic form filling for those failed forms. It's nice to have the select box, for instance, come up to the correct option.

  • It's a well known framework. Don't have to teach people much.

Why I don't like it:

  • No support for action name with wildcards. For instance, you can't setup a mapping for /person/*. There is some hacking you can do, but it only gets you half way. In the <html:form> tag, you can't use those wildcards without hacking the source deep down.

  • Too much emphasis on verbs instead of nouns. Here is my major beef with Struts. It wants you to think in terms of Actions (such as or This is too RPC for my tastes. We've been taught that the WebArch likes URIs that identify nouns. The HTTP method (GET or POST) is what identifies the action. Struts makes this too hard. It's fairly possible to work with struts where the Actions become nouns, but it's not pretty.

  • Struts' I18N uses some weird class MessageResources instead of the standard ResourceBundle like the rest of Java's I18N implementations. We had to write an Adaptor from one to the other. This usually isn't the case when using property files for translations, but we are using Java classes for the translation resources. Why a separate class?

  • Often times, I need to do validation inside the Action. That's OK, but then I have to bypass Struts' auto-validation. That's OK, except that it's one of the main reasons I even use the framework! There may be a way around this. I know that FormBeans have a validate() method, but that may overridden when it's a ValidatorFormBean. Can I have Validator automatic validation plus custom validation logic in a form bean?

I think there are other quirks in there. My main problem with Struts is it is trying to apply a GUI design principle (MVC) to the Web. I'm not convinced it's a perfect way to think about things.

I would like the framework to be more REST friendly and treat everything as a set of Resources, not Actions.

Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart