Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamic global result in struts2 xml

Tags:

struts2

My need is to have a global result in struts.xml in having the dynamic value for the action to be redirected to. Like,

<global-results>
    <result name="customResult" type="redirectAction">
    <param name="actionName">${customValue}</param>
    <param name="namespace">/</param>               
    </result>
</global-results>

This customResult is being returned from one of my interceptor. customValue is the member of the same interceptor with getter and setter.

I am aware that action specific results can have dynamic values in it, provided the dynamic param shuould get its value assigned in the execute method of the particular action. And, that dynamic param should be the member of that action class.

Since here it is needed in global result, I made the dynamic param to be the member of the interceptop where I return that particular global result. But, this ${customValue} is not getting values while redirecting. It simple gets redirected to localhost:9080/myapp/.action.

Please suggest

like image 256
IamSan Avatar asked Apr 17 '26 10:04

IamSan


1 Answers

The action properties will be put into the value stack that is why when you have an expression (like ${customValue}) in configuration, the values will be retrieved with appropriate getters. In order to achieve same behavior inside an interceptor you can put desired values directly into the value stack. The value stack can be retrieved from the invocationContext.

invocation.getInvocationContext().getValueStack()
              .set("customValue", "some_action");
like image 135
Aleksandr M Avatar answered Apr 22 '26 12:04

Aleksandr M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!