Refactoring in the web tier?

We are developing a Tomcat based webapp. We follow the Maven standard directory layout, with java source files in /src/main/java and JSP files in /src/main/webapp. /src/main/java is marked as a src folder and /sr/main/webapp is marked as a web folder respectively.

We also use Struts 2 extensively. The problem becomes that if we refactor - say rename an action class - the refactoring breaks in the web tier.

Say I have an action class MyFirstAction and I rename it to MySecondAction - the java code refactoring works fine. But the struts.xml file is not refactored. Ok no problem I can deal with that. I go into the file and rename the action mapping "MyFirst" to "MySecond". Here's where the problem kicks in - all over my JSP pages I have hyperlinks to that action mapping in the form <s:url action="MyFirst"/> - all of them are broken now cause they did not get refactored! I can't even find places in the JSP where that symbol is used, except for a text search in path. So whilst the code level refactoring is excellent, I am in danger of breaking my web tier in multiple places.

Is there a way I can easily do this? My current method of text search in path is a bit error prone. If there's not an easy way, how do I suggest web tier refactoring as a feature for a future release?

Also I should add that IDEA knows when the action is missing cause it highlights the tag in red. But my problem is that I have to know which JSP files to open to see that red tag. The whole point of using the Struts tags is so that the server can look up the right URL for the symbol and I shouldn't have to worry about it. If the symbol changes then references to that symbol should change too - just like it does in code refactoring.

2 comments
Comment actions Permalink

Hello Raj,

Say I have an action class MyFirstAction and I rename it to MySecondAction - the java code refactoring works fine. But the struts.xml file is not refactored. Ok no problem I can deal with that. I go into the file and rename the action mapping "MyFirst" to "MySecond".


why should the action-mapping automatically be renamed?

Here's where the problem kicks in - all over my JSP pages I have hyperlinks to that action mapping in the form <s:url action="MyFirst"/> - all of them are broken now cause they did not get refactored!


How did you perform the refactoring, via Refactor->Rename? It should automatically correct all paths, whether they are in struts.xml or JSPs. If not, please provide an easy-to-reproduce testcase or simple project.

Thanks,

Yann

0
Comment actions Permalink

Oh I see. I can't remember exactly what I did before but I just tried the method you suggested and it worked perfectly. Thanks.

0

Please sign in to leave a comment.