Peter Kelley
Peter Kelley

Reputation: 2360

How do you obtain the value of struts.action.extension in a struts2 interceptor?

I need to access the struts.action.extension value in the struts.xml file from an interceptor. Any suggestions?

Upvotes: 0

Views: 583

Answers (2)

rgb130
rgb130

Reputation: 100

I realize the answer is probably for a previous version of struts, it did not work in the version of struts I'm using (struts v2.2). The following did work, though...

final ActionContext context = actionInvocation.getInvocationContext();    
com.opensymphony.xwork2.util.ValueStack vs=context.getValueStack();
((ActionMapping)vs.getContext().get("struts.actionMapping")).getExtension();

... where ActionMapping is org.apache.struts2.dispatcher.mapper.ActionMapping.

Thought it might help someone.

Upvotes: 1

Peter Kelley
Peter Kelley

Reputation: 2360

Thanks to Musachy Barroso over on the Struts User list I added the following to my interceptor:

/**
 * @param strutsActionExtension the strutsActionExtension to set
 */
@Inject(StrutsConstants.STRUTS_ACTION_EXTENSION) //Note this isn't necessarily supported
public void setStrutsActionExtension(String strutsActionExtension) {
    this.strutsActionExtension = strutsActionExtension;
}

as Wes Wannemacher notes on the same list this in't actually supported but is extremely unlikely to change in future releases.

Upvotes: 0

Related Questions