Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts 1 - Refactoring actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1 - Refactoring actions" Watch "Struts 1 - Refactoring actions" New topic

Struts 1 - Refactoring actions

Ivan Pazmino

Joined: Mar 24, 2010
Posts: 6

I'm trying to refactor some classes in a project that uses Struts 1. The big problem here is the Action class holds one big if that resolves the forwarding according to the button which has been pressed. This class extends the Action class and overrides the execute method to return the ActionForward.

The first approach is to make at least a method for each button, but still I have a 5 - 6 options if. I'm kind of new to this framework, so I'm sure I can use your suggestions for a better refactoring process.

Thanks in advance.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30068

Welcome to JavaRanch!

Can you refactor just the forward part by moving it to a different class that the action calls?

It's hard to provide comments on how to refactor a class without seeing it.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David Newton

Joined: Sep 29, 2008
Posts: 12617

This is what DispatchAction (and its brethren) are for.
I agree. Here's the link:
subject: Struts 1 - Refactoring actions
Similar Threads
problem with LookupDispatchAction
neither action class called nor jsp page displayed
how to define functionality for 2 buttons in an action form
isCancelled(request) not invoked
problem with submit and redirection {javascipt struts under google chrome}