File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
author & internet detective

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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
It's not a secret anymore!