This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All that could be configured in a config file, by convention, by packages, etc.
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic