My Own Struts Best Practice

14 October 2004

In response to all the Struts Action Chaining searches I see, I'd like to relate my experience, and the advice I found when struggling with chaining.

Keep your Struts actions very thin and lightweight. Don't code your business logic into Struts actions, then try to reuse them through chaining. Inheritance may not be such a hot idea either, though I do this for centralizing some web-tier session work like security checks. Otherwise, do yourself a favor and code your own plain objects and APIs to do your business. You are free to introduce as much architecture there as you like, including chaining. Don't fear creating your own object hierarchy. Just because you're coding within a framework doesn't mean every class you create must extend a class or implement an interface from that framework.

I was caught in that trap for a long time with EJB and servlet programming. Realize that you're still writing your own program, just with a framework for the web front-end. This will allow you more freedom to migrate frameworks too.

(I know the latest Struts has introduced Struts-Chain based on commons-chain, but I've not looked at it yet. This is probably an appropriate approach, but I doubt the commons-chain API requires javax.servlet.* or other web APIs, so it'll still exist as separate and decoupled code.)


Filed Under: Java Blog-Code