there were 2 approaches to getting a custom stack to work (using the convention plugin).
approach 1: use annotations. for example, use @ParentPackage("default") for each Action class you want to use your custom stack. also, use @InterceptorRef for each method that you want to use your custom stack. why do you have to use @ParentPackage("default")? here's a non-formal answer. when you use the convention plugin, the namespace is not "default" but "convention-default". i "infer" that defining a custom stack is placed in the "default" namespace, but if you use the convention plugin, your actions will be passed through the "convention-default" namespace and associated stacks. since your stack is in the "default" namespace, the stack won't ever get called (even if you set it as the default!). hopefully other struts 2 gurus can give us more formal/precise answers. why do you have to use @InterceptorRef? tell tell struts which stack to use for this action (within the namespace defined by @ParentPackage). approach 2: simply add 1 line to struts.xml. before the <package ...> ... </package> declarations, add <constant name="struts.convention.default.parent.package" value="default"/>. using this approach, you don't need to use annotations at all. also, with this approach, it's a one-hitter-quitter, because you don't need to do @ParentPackage and @InterceptorRef for every class/method. the "default" namespace will be used, and the custom stack will be called on every request (assuming you use <default-interceptor-ref/> to select your custom stack as the default stack). hope that helps. On Sun, Jan 31, 2010 at 2:24 PM, Leah OConnor <leahocon...@sbcglobal.net> wrote: > Thank you for posting your solution. I aso read >> http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-XWorkpackages >> > several times and do not see the connection. I'm not sure I understand > exactly what you > did solved the problem, but it is clerarer than the documention > > > --- On Sat, 1/30/10, Jake Vang <vangj...@googlemail.com> wrote: > > > From: Jake Vang <vangj...@googlemail.com> > Subject: Re: interceptor is not being called for all action > To: user@struts.apache.org > Date: Saturday, January 30, 2010, 5:38 PM > > > okay, to answer my own question, yes, if you configure everything correctly, > then you can get a customized stack to work for all Actions. the only thing > you really need to do is add this line to struts.xml > > <constant name="struts.convention.default.parent.package" value="default"/> > > with this defined, you can remove the @ParentPackage and @InterceptorRef > from the classes and methods. > > wow, it was that easy. > > On Sat, Jan 30, 2010 at 6:14 PM, Jake Vang <vangj...@googlemail.com> wrote: > >> okay, after fiddling around for 2 hours, with the weak documentation out >> there, i think i have it figured out. at least empirically, it works now. >> just in case there are other users out there who are running into this >> problem, let me explain what in the world i did. i know A LOT of other >> people have run into this problem on how to get interceptors to work with >> the convention plugin (googling). the shame is that although i saw a lot of >> "thanks, i got it working", no one ever bothered to show how they got it to >> work. >> >> at any rate, if you read the original post by me, you will see how my >> interceptor stack was defined in struts.xml. you will also see how i >> implemented a dummy interceptor. i had to do two things to get my >> interceptor working (called on my action). >> 1. add @ParentPackage("default") to my Action class >> 2. add @interceptorref...@interceptorref("dummyStack") to my execute method >> (in my Action class). >> >> after i did this, my interceptor's intercept(ActionInvocation) method is >> called when my Action is called. >> >> here's how my dummy Action class looks like. >> >> @ParentPackage("default") >> public class DummyAction extends ActionSupport { >> @Action(value="/dummy", >> result...@result(name="success",location="dummy-success.jsp")}, >> interceptorref...@interceptorref("dummyStack")} >> ) >> public String execute() { >> return SUCCESS; >> } >> } >> >> alright, so, now i'd like to know how to get this interceptor stack >> (dummyStack) to work on all actions? in the link i posted, you can do so >> using one single line in struts.xml (i.e. <default-interceptor-ref >> name="dummyStack"/>). with the convention plugin + annotations, is such a >> simple approach possible? or do i have to continuously add @ParentPackage >> and @InterceptorRef annotations to the classes and methods i want to use the >> stack? >> >> i don't know why this is such a pain (but then again, i'm not a developer >> on the struts2 project, so there may be a lot of complexities to get this >> working elegantly that i'm unaware of). >> >> On Sat, Jan 30, 2010 at 4:10 PM, Jake Vang <vangj...@googlemail.com>wrote: >> >>> i have written an interceptor implementation, however, it seems i cannot >>> get it to work. i have followed the instructions at >>> http://struts.apache.org/2.x/docs/interceptors.html. i have also followed >>> the instructions at >>> http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto >>> use the interceptor with every action. >>> >>> however, when any of my actions run, i never see the pre and post >>> processing logging messages (logging messages inside the intercept method). >>> i do see the logging messages from the init and destroy methods. this is not >>> a problem with logging (as for sanity checking, i also use >>> System.out.println, and have Tomcat running in console mode). i also have >>> placed some break points in the intercept(ActionInvocation) method, but >>> these break points are never reached. >>> >>> this is my struts.xml. >>> >>> <struts> >>> <package name="default" extends="struts-default"> >>> <interceptors> >>> <interceptor name="dummyInterceptor" >>> class="mypackage.DummyInterceptor"/> >>> <interceptor-stack name="dummyStack"> >>> <interceptor-ref name="dummyInterceptor"/> >>> <interceptor-ref name="defaultStack"/> >>> </interceptor-stack> >>> </interceptors> >>> <default-interceptor-ref name="dummyStack"/> >>> </package> >>> </struts> >>> >>> this is my DummyInterceptor class. >>> >>> public class DummyInterceptor implements Interceptor { >>> private static final Log _log = >>> LogFactory.getLog(DummyInterceptor.class); >>> public void destroy() { >>> _log.debug("dummy interceptor destroyed called"); >>> System.out.println("dummy interceptor destroyed >>> called".toUpperCase()); >>> } >>> public void init() { >>> _log.debug("dummy interceptor init called"); >>> System.out.println("dummy interceptor init called".toUpperCase()); >>> } >>> public String intercept(ActionInvocation actionInvocation) throws >>> Exception { >>> _log.debug("dummy interceptor intercept pre processing"); >>> System.out.println("dummy interceptor intercept pre >>> processing".toUpperCase()); >>> >>> String result = actionInvocation.invoke(); >>> >>> _log.debug("dummy interceptor intercept post processing"); >>> System.out.println("dummy interceptor intercept post >>> processing".toUpperCase()); >>> return result; >>> } >>> } >>> >>> i am using annotations for my Action classes, so i do not define any >>> <action> elements in struts.xml (using the Struts2 Convention jar). >>> >>> one very interesting thing i did was to get struts-default.xml out of the >>> struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding: 1) a >>> definition of my interceptor and 2) my interceptor onto the defaultStack. >>> when i did this, my interceptor does work as expected (i see logging output >>> from the intercept method, i can hit break points set inside this method) >>> for all my actions. >>> >>> i wonder if there is some gotcha that i am missing here. is there >>> something extra that i have to do when mixing annotations with interceptors? >>> >>> thanks. >>> >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org