WebWork Doc-a-Day; Struts Really Sucks
With the upcoming release of WebWork 2.0 beta 2 (just waiting for Ognl 2.6.4 to be released), I'm going to begin a document-a-day effort on my blog. Essentially, I'm going to document some feature at least once a day and post it here. Hopefully someone will consolidate these in to a real document :)
To kick off this announcement, I'm going to point out yet another reason why Struts is really bad (I won't say sucks, I already said that in my title :P). Look at this taglib, last commited by Craig McStruts himself.
There are two important things to note here:
Object args[] = new Object[] { arg0, arg1, arg2, arg3, arg4 };
That is the code that constructs the arg list for internationalizing messages. Notice something terrible bad here? No? Let me spell it out: your i18n messages can only have four arguments! I guess you better start chopping your messages up to support Struts.
The bigger, more annoying thing that this implies is that the number of args is not dynamic. The args are specified as tag attributes arg0, arg1, arg2, and arg3. And since these attributes aren't evaluated against any sort of expression language, the only way to use dynamic values for these args is to either use javascript (NASTY) or to use <%= someString %>. Both suck.
There are a few things going on here. In WebWork, this could be done by doing:
<ww:text name="'i18n.key'"> <ww:param value="someExpr"/> </ww:text>
- dynamic number of params are supported
- easy access to a bean property via someExpr
In Stuts "someExpr" wouldn't work because the only way to access bean properties (formbeans) is via the bean:property tag. And of course, you can't do a JSP tag in the attribute of another JSP tag (at least not in pre-2.0 days, not sure about post-2.0).
The most disturbing thing of all this is that no one in the Struts community has complained (at least enough) for this to change? This is just typical of Struts users -- they either don't develop any real applications that demand a good framework, or they just live with Struts acting as a very poor wrapper around raw servlets.