Hi all,
I would be very interested to hear of different opinions, experiences and uses regarding wildcard mappings.
I started using Struts2 some months ago. Very quickly, I decided I would use wildcard mappings - they seemed neat and kept the struts2 configuration xml files tidy. I left validation of
jsp pages until towards the end... Consider the following action mapping as an example:
I have the corresponding methods add() and edit() in my AccountAction class.
The trouble I found with wildcard mappings is that I can only map one result with the name "input". When validation failed, result name "input" was returned. If validation failed for add, I wanted to forward to add.jsp (to give the user another chance to add an account and display the errors). If validation failed for edit, I wanted to forward to edit.jsp. Therefore, I was unable to distinguish which page I wanted to go to when validation failed and I got result name "input" back from either of the action methods.
I found some solutions.
1) I can store the destination page in a variable in AccountAction. Therefore, when edit() is called, I could set the
String inputDestination to "edit.jsp" and in my result mapping have:
Although my action must now know about jsp pages and their names, and set the correct input destination in each method.
This seems a little wrong to me... I'm working around an issue that shouldn't exist.
2) I experimented by writing a new Workflow interceptor. This basically returned "input" with "_methodName" appended, rather than just "input". So if validation of edit Account failed, my custom Workflow interceptor would return "input_edit" as the result name, allowing me to handle different validation failures. But this seemed wrong.
I am currently not using Wildcard mappings for this reason. Any thoughts on ways around this issue (or my own two proposals) would be greatly appreciated!
Thanks for reading!
James