This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamically created urls/action calls in Struts 2

 
Fletcher Munson
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic