views:

123

answers:

2

I have the following code in struts.xml:

<interceptor-ref name="checkTabsStack">
 <param name="tabName">availability</param> 
</interceptor-ref>

and I want to access the parameter tabName in the interceptor routine, how do i do that? i tried

Map params = ActionContext.getContext().getParameters(); 

but params comes empty...

Thanks!

+2  A: 

An Interceptor object should know nothing about the piece of xml that was used to create/configurate it, that is something internal to Struts2. Think of it: a interceptor class (eg) does not have some "params" attribute, and it might even be (in theory) instanced by some mechanism that has nothing to do with the struts.xml you post. This is decoupling, and Struts2 takes that seriously.

True, some interceptors have some configurable parameters; but they will normally be properties of the particular class. In your example, your particular interceptor class (which you should know) might have probably the methods setTabName() getTabName(). The setter will be called by struts2 when reading the struts.xml file and instantiating the interceptor. The getter is what you should be looking after. Look into your interceptor class docs.

leonbloy
ok, i fixed my problem by reading the action params inside the interceptor; i still need to have a class associated w/ the action to do this though..
Ricardo
A: 

In your interceptor class:

public void setTabName(String tabName) {
    // ...
}

Struts will call this setter when the interceptor is initialized.

Todd Owen
tried that before but i dont get any value in the getter inside the interceptor class...
Ricardo