After working with Struts for a while, all our action implementations have become fat with code bloat.
Anyone else encountered the same situation? I'd love to hear how you got around this problem and any refactoring you performed!
Do you have business logic in your Struts Actions? Do you have data access code in your struts actions? Those are great places to factor. You should keep your business logic, in a set of classes outside your Struts Actions, you should also keep your data access code outside in a set of classes outside your business logic. I have found that my Struts Actions are tiny when I do this.
Good suggestions, here are a few others. These assume Struts 1.1
1) Consider using an AbstractBaseAction where you can place common functionality used across all actions. You might even have multiple abstract actions classes that form a hierarchy of sorts.
2) Consider using Dynamic Exception handling. If your actions container try/catch blocks, you can get rid of this by using the 1.1 feature for exception handling.
3) Just to reiterate the previous comments; your actions should container no business logic whatsoever. You should use a service-oriented interface and encapsulate your business logic behind these interfaces and your actions should call them to perform the logic.
Just a few thoughts,
Author of Programming Struts by O'Reilly