Struts Action Chaining Is So Damn Tempting

The Chain of Responsibility pattern is so useful for what I'm doing. I'm displaying a blog article, its associated comments, and a form to post more comments. I implement it as a ShowArticle action, which upon success forwards to ListComments, and that forwards to the view JSP. When I try to submit a new comment, the SaveComment action grabs the ActionForm, twiddles it for a preview, then forwards back into this previously detailed sequence of actions. This is called action chaining, and it's bad.

My first sequence works fine, because I'm only committing changes to the request object, but I illustrated a problem when I tried to propogate changes to the Struts Action Form. The ActionForm gets reset() to its submitted values for each action in the chain, so I lose my modifications from the first Action when it jumps to the second Action.

Struts doesn't intend to implement the Chain of Responsibility pattern. I'm supposed to do that for myself in my business logic. This means I need to be smarter about all this and refactor more of my presentation logic further down into the EJB business tier or into its own modularized logic tier between business and straight web stuff. It's going to be a bit difficult to keep straight for a bit, but I'll figure it out, and it'll hopefully make maintenance easier.

Once I get my preview stuff working nicely again and the tiers seperated further, I can get back to my track back message bean.


Filed Under: Java Blog-Code