While I'm at it, other common methods that don't necessarily belong to
Action, but are common enough to be in Struts somewhere:  (IMO,
obviously)

        getInt(request, attributeName);
        // and other common types, Date, Integer, Long ...

Interesting that Struts lacks probably the first Servlet utility ever.
Or am I missing something?


getInteger(form, property); // handle all ActionForm and DynaActionForm

I think various resources in commons-lang and commons-beanutils support these kinds of operations, and putting direct support for them in Struts is more like clutter than value. I'll admit that I'm writing little methods like this (my most common is "isEmpty(...)" which combines a null check with a standard "emptiness check" (string length, collection size, etc)) The problem is that everyone has their own favorites and it would be a mess to figure out exactly which ones and which peculiar variations on similar things are "in" or "out" -- simpler just to leave 'em all out.


Anyway, does it make sense to have something like this:

        saveError(request, errorsKey, messageKey)


I usually end up adding that to a "BaseAction" in each project, but maybe it doesn't belong in Action, per se.

On the other hand, this to me is more central to Struts itself, and so might be worthy of inclusion. Here's an alternate approach we use: first, we have an "ActionContext" which carries the ActionForm, ActionMapping, HttpServletRequest and HttpServletResponse around, rather than passing all four independently. This ActionContext then has some utility methods that are based on how Struts deals with those -- for example, it has properties for two ActionMessages objects, one representing "errors" and one representing "messages". Then actions can call "context.addError(errorsKey, messageKey)" as a convenience like what you describe above, except that the context already has the request. (Of course, there's a addMessage(...) method also, and versions which accept ActionMessage objects for cases when you have a replacement value array to pass in also).


The problem is that even these things are fairly idiomatic, and what we find convenient here might be fairly contentious among the wider world of developers. (Let's see if any sparks fly here :^)

Joe

--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn back; I'll know I'm in the wrong place."
- Carlos Santana


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to