aspose file tools*
The moose likes Struts and the fly likes dynamically created urls/action calls in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "dynamically created urls/action calls in Struts 2" Watch "dynamically created urls/action calls in Struts 2" New topic
Author

dynamically created urls/action calls in Struts 2

Fletcher Munson
Ranch Hand

Joined: May 16, 2007
Posts: 31
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.


SCJP 5, SCWCD 1.4
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamically created urls/action calls in Struts 2