• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Action Mapping - Wildcard Methods - Good or Bad? (Struts 2)

Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not a big fan of wildcard mappings, although for simple usecases, they're okay. But I also don't like mashing a bunch of functionality into a single action, either, unless it's super-closely related. In the case you show first, though, you're not using the method name in the JSP result--the wildcards are available in the mappings just like action properties are, so "input" could be mapped to "{1}_account_input.jsp" or whatever.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic