This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Calling an interceptor twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Calling an interceptor twice" Watch "Calling an interceptor twice" New topic
Author

Calling an interceptor twice

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
I got to see below code on http://www.opensymphony.com/webwork/wikidocs/Prepare%20Interceptor.html




My question is, how to call same interceptor(in this case prepare interceptor) twice?


I am slow but sure
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Why do you need to call it twice? Can't you just have logic that occurs both before and after the call to proceed to further interceptors?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

The original poster is asking why the documentation says the interceptor is called twice with the configuration he posted (see his link).
The way I understand it, the "params" interceptor is invoked once explicitly in the configuration above, then invoked again in the "basicStack" (see the default configuration).
As to why one would do this:
A typical use of this is to run some logic to load an object from the database so that when parameters are set they can be set on this object. For example, suppose you have a User object with two properties: id and name. Provided that the params interceptor is called twice (once before and once after this interceptor), you can load the User object using the id property, and then when the second params interceptor is called the parameter user.name will be set, as desired, on the actual object loaded from the database.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
Thanks Joe
>>>The way I understand it, the "params" interceptor is invoked once explicitly in the configuration above, then invoked again in the "basicStack" (see the default configuration)

Your comment made me understand why the interceptor is called twice. once via explicit call and once via basicStack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling an interceptor twice
 
Similar Threads
struts2: what kicks in first- the interceptors or the form's validation?
Overriding default interceptor stack
Confused with Built in Inerceptors in Struts2
ModelDriver Interceptor + not getting my object
Struts 2 file upload tag type allowed error