I'm certainly not the most experienced Struts person around, so weigh my opinions 
accordingly. However, it's repeatedly occurred to me that one of the "barriers to 
entry", so to speak, of using Struts is the rapidity with which Action classes 
proliferate. The project we're working on, which will eventually be fairly large but 
so far isn't, has dozens of Action classes. It approaches one per page that could be 
displayed.

Perhaps there's a design pattern that we've missed which would alleviate this. But 
apart from looking at the request path during "perform" and then acting conditionally, 
which is very brute force, I don't see a lot of options. I believe it would be 
preferable to have a single Action class in which all related activity occurs. This 
makes it easier to add new "logical" actions. More importantly, however, it greatly 
eases maintenance in the case where you need to change a lot of related/similar code 
(maybe a back-end API changed).

Here's one question: Would it work to specify an inner class as the "type" for an 
action? For example (pseudocode):

public class OrderActions
{
    public class Query extends ActionBase
    {
        ActionMapping perform( ... )
    }

    public class Edit extends ActionBase
    {
        ActionMapping perform( ... )
    }

    public class Save extends ActionBase
    {
        ActionMapping perform( ... )
    }
}

I think you get the point.

Assuming that I'm not completely missing something, here's what I'm thinking of as an 
enhancement. Add a "method" attribute to the "action" element in struts-config.xml. If 
present, the ActionServlet would call this method (using introspection or whatever 
makes sense); if it's not present, then call "perform" as we do now; if the attribute 
is specified but the method doesn't exists, it's an exception.

Thoughts???

Thanks,

Donnie

Reply via email to