• 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

dynamically created urls/action calls in Struts 2

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a list of transactions beans I need to display to a user. I also need to provide edit links for each transaction. Now each transactions has to go to it's own transaction type page when a user hits the edit link. Each transaction type processes in a different manner so I would like to put these in seperate actions (all extending a base action). I don't know the transaction type until I'm writing the bean to the user interface. So my question is how can I dynamically define my action in my s:url tag? Below is my current tag setup. What I would like to do is replace the action="editTransactionAction" with something dynamic.

The transaction bean does have a type so it would be possible to call transaction.type to get a string value so I'd like to do something like:

action="transaction.type + Action"

Can anybody help set me straight here?

And yes, that is a struts 1 <bean:write> tag - we are in the process of converting our app, and some pages are mixed.
 
Author
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
The struts-user list has had some threads about creating dynamic actions; I don't recall the outcome of the debate if the "action" attribute is evaluated via OGNL. If it *is* evaluated then it's a simple matter of doing something like %{trans.type + 'Action'}, but again, that's only if it's evaluated.

It may be easier just to create the link manually. FWIW, the <s:a...> tag is mostly for the Ajax theme; there's no good reason to use it if you're just creating regular links--it's probably more efficient to just use plain old HTML anchor tags.

There's also no real good reason to use <bean:write...> -- if it's a normal scoped object you can just use JSP EL, ${transaction.id} -- and if the transaction is already in scope, which it must be in order to create the action URL the way you want, using <bean:write...> seems redundant.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic