Hello,
exists there any (easy) possibility to equalize the action forward
patterns in
struts config with static
Java constants?
"Easy" means without parsing the files with any other language and to textual replace the strings.
The example below defines some mapping constants, uses them in action and in struts-config.xml.
WebConstants.java:
public interface WebConstants {
public static final
String SUCCESS = "success";
public static final String FAILURE = "failure";
}
Action.java:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward forward = mapping.findForward(WebConstants.FAILURE);
if(form != null) {
...
forward = mapping.findForward(WebConstants.SUCCESS);
}
return forward;
}
struts-config.xml:
<action path="/ConfigInit"
type="app.myTest.struts.action.ConfigInitAction"
scope="session" >
<forward name="success" path="/ServerConfig.do" contextRelative="false" />
<forward name="failure" path="/errorFwd.do" contextRelative="false" />
</action>
In the example the WebConstants.java file contains static string constants for SUCCESS and FAILURE. In struts-config.xml the content of the definitions is used in the name attribute of the forward declaration.
In a greater software project you may have many different constants and many different labeled forward "names".
Exists there a solution to avoid misspelling in these two places?
Thanks
Chris