views:

335

answers:

2

I have a default package w/ an interceptor configure, and i'm extending that package into another one and calling the same interceptor

<action name="availability**">
            <param name="subTab">availability</param>
            <interceptor-ref name="tabStack"/>          
            <result>/WEB-INF/jsp/index.jsp?include=visibilit/availability.jsp</result>                      
        </action>

The problem is that the param is not being read inside my interceptor code:

Map params = invocation.getInvocationContext().getParameters();
subTab = params.get("subTab").toString(); //NULL exception

Any idea how i can pass parameters to extended interceptors?

Thanks!

A: 

Can you try this syntax

<action name="availability**">
<interceptor-ref name="tabStack">
     <param name="subTab">availability</param>
</interceptor-ref>
</action>

I am not sure but maybe this will work

VinAy
tried that and not working, i suspect it's a bug (or unintended feature) on struts2
Ricardo
The funny thing is that if i declare the interceptor inside the package, then it works ;)
Ricardo
Maybe we can define parameter at the time of Interceptor declaration and not while referencing it
VinAy
A: 

The getParameters() method which you are calling only returns the parameters from the HTTP request. The parameters set in struts.xml with are called "static parameters", and you can access them (within the intercept() method) like this:

ActionConfig config = invocation.getProxy().getConfig();
Map<String, String> parameters = config.getParams();
String subTab = params.get("subTab");

Source: StaticParametersInterceptor.java

Todd Owen
Thanks Todd. My code is working fine and is extracting the static parameters. My problem was that i placed the tabstack before the defaultstack in my stack def, and struts was not populating the params map. cheers
Ricardo
Yes, the staticParams interceptor will by default add the static parameters to the request's parameter map. But if you are using this method to access the parameters, you should be aware that the user could override them by adding "?subTab=xyzzy" to the end of the URL. Request parameters take precedence over static parameters, unless "override" is set on the staticParams interceptor.
Todd Owen