wood burning stoves 2.0*
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
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30965
    
158

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: 8971
    
    9

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.


[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