aspose file tools*
The moose likes Struts and the fly likes S2: Can you find out the action name you called in the displayed screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "S2: Can you find out the action name you called in the displayed screen" Watch "S2: Can you find out the action name you called in the displayed screen" New topic
Author

S2: Can you find out the action name you called in the displayed screen

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi,

Is there a bit of code, EL, tag etc that I can call in a JSP that will work out what action I called that created the screen?

For example, if I called products!show and that action forwarded to productsShow.jsp could I work out in productsShow.jsp the first request was products!show

What I want to resist doing is passing down a parameter to the JSp from the action, rather the JSP is smart enough to work out where it came from.

Thanks in advance
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm sure it could be gotten from the action invocation, but why? Sounds like a recipe for poor maintainability to me.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:I'm sure it could be gotten from the action invocation, but why? Sounds like a recipe for poor maintainability to me.


I'm pretty sure the action invocation is long gone by the time you are in the JSP, or at least I cannot find it anywhere.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I can however look for struts.request_uri on the request but that comes with the context prepended which is not completely ideal.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

ActionContext.getContext returns the thread-local ActionContext, which contains the ActionInvocation.

Again--why would you want to do this? A "smart" JSP seems like a leap backwards.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:ActionContext.getContext returns the thread-local ActionContext, which contains the ActionInvocation.

Again--why would you want to do this? A "smart" JSP seems like a leap backwards.


Every page on the site has a register link, I want to place the last action in a param for the register action class to pick up before it goes of on a 3 screen register use case, then I can go back to where the user came from when the user has registered by recalling where the action.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I guess I'd handle that differently and keep that kind of logic out of the JSP page.

I try to keep my JSP pages as brain-dead as possible and encapsulate logic like that into interceptors and/or actions.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
I have tried to do that before with an interceptor and it just ends up a bit of a mess because you end up having to filter out pages in the interceptor where you do not want to record the page.

if( in page that you do not want to record) {
// forget
}
else if( in another page that you do not want to record) {
// forget
}
else{
// record page
}

Sometimes the hacks you think of first are the best solutions.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

All that could be configured in a config file, by convention, by packages, etc.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:All that could be configured in a config file, by convention, by packages, etc.


If you could tell me a convention that can do what I asked then I am all ears. Educate me.

How could I configure a convention to work out how to return to a specific page?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I know nothing about your application--I don't see how I could figure out a convention that would work for you.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:I know nothing about your application--I don't see how I could figure out a convention that would work for you.


"Sounds like a recipe for poor maintainability to me. "
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And?

Keeping logic in JSPs is bad--that's why there's other options. You asked me to come up with a convention for *your* application--how could I possibly do that? *You* could do that, because you know your URLs, your areas of functionality and/or responsibility, etc. *I* can't, because I know nothing about your application.

I provided other options: use packages, configure the interceptor per-action in your config file, create a convention. Mark actions with a marker interface. Use annotations.

The ultimate goal is to keep logic, particularly *application* logic, out of your JSPs.
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
David Newton wrote:And?

Keeping logic in JSPs is bad--that's why there's other options. You asked me to come up with a convention for *your* application--how could I possibly do that? *You* could do that, because you know your URLs, your areas of functionality and/or responsibility, etc. *I* can't, because I know nothing about your application.

I provided other options: use packages, configure the interceptor per-action in your config file, create a convention. Mark actions with a marker interface. Use annotations.

The ultimate goal is to keep logic, particularly *application* logic, out of your JSPs.


Yes, you do not know anything about my application, but are prepared to pick holes in how that application is written.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Absolutely: keeping logic in JSP, particularly when there are any number of better options available, is a bad idea. I don't *care* if you do it that way, but I don't understand it, either.

I'm sorry you're mad I don't think putting application logic in a JSP is a good idea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: S2: Can you find out the action name you called in the displayed screen