• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Equalize Java constants and struts-config.xml entries?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid there's no easy way to do this. Struts simply reads in the configuration file at startup time and does not allow for inserting constants from classes.

If you wanted to do this, you'd have to write your own extensions to Struts and devise a symbol for indicating that the text should be replaced with a constant in a java class.
 
Chris Wimmer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your suggestion to extend Struts and to let the ModuleConfig implementation do the replacement is a good idea. I've not thought about this till now. Thank you very much for that hint.

Ciao

Chris
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic