• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope interceptor: scope.type = end not doing any cleanup.

 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm having an issue with the Scope interceptor provided in Struts 2.1.8.1. It works great for putting the specified object into my session and prepopulating it with the data recieved from struts forms. However, when I complete the final step I would expect that the session would be cleaned up (i.e. my object removed automatically by Struts). Struts is not doing this cleanup nor throwing any error or warning to indicate why.

The reason I'm expecting this behavior is because that is what the API states: http://struts.apache.org/2.1.8.1/struts2-core/apidocs/org/apache/struts2/interceptor/ScopeInterceptor.html

I've pasted my config xml file for this particular package below. I know that this functionality is usually reserved for 'Wizard like' interfaces, but I'm using this basic 2 jsp example to illustrate my point. I start using the scope interceptor in action initCostType and I end in editCostType.

initCostType is used for preparing and displaying my values for user input.

editCostType is used for storing the data. I know that normally you should not have your save action the same as your end of scope, but it doesn't make a difference as far as I can tell. Please prove me wrong.



Has anyone else experienced this issue? The more research I do the more books I find stating how to use the scope interceptor. However, if I copy and paste the examples given in my IDE and run them, there is no session cleanup. I'm starting to suspect it's a Struts 2.1.8.1 problem.

Thanks for any help.
Michael
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the flow you're taking through the app, and where/how are you determining the value is still in session? I mean, the code to remove the value is in the interceptor (see below), and it's pretty much the same as adding the object to the session, except in reverse.I can't do any testing of this at the moment, but I'll try to remember to look at this tomorrow.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(My initial guess is that using "scope.type" as a parameter name when you're directly referencing an interceptor won't work; that's really only intended for when you're dealing with a stack of interceptors, and I'm not sure that OGNL would figure out what you mean. I don't know if I'll be able to test that tonight, though.)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reproducible using the incorrect param name "scope.type"; try using the correct param name "type".

Edit: In my test code it's only the "end" scope.type param that causes a problem--because of the way the interceptor is written.

In other words, the "start" action may work with the incorrect param name, but the "end" action will not. Do it right in both places, however, as there may be circumstances under which a mis-configured "start" action would cause issues.
 
Michael Freake
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David,

Just tested what you believed to be the problem (i.e. 'scope.type' should be 'type'). You are correct. That is exactly what my problem was. Now, if I go completely through the wizard in my application, the Scope interceptor does clean up my session.

Thanks for your help.
Michael
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good deal; glad you got it working.

I do need to make a documentation change, though; it incorrectly states that setting "type" to anything other than "start" or "end" doesn't do anything, but it'll actually throw an exception.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Followup: change made in the interceptor's Javadocs; also working on test class, app samples, and minor refactoring.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic