简体   繁体   中英

How invoke Action method by variable on Struts 2?

How can I invoke action method by variable? To explain better, this code works

<s:action name="indexController!loadData" executeResult="false" />

... But this other one doesn't work

<s:action var="mainController" name="indexController" />    
<s:action name="mainController!loadData" executeResult="false" />

... I also tried

<s:action var="mainController" name="indexController" />    
<s:action name="#mainController!loadData" executeResult="false" />

But it doesn't work too. I need the second mode, because I must switch action dynamically on the page.

In the name attribute you need to force the OGNL evaluation with %{}

Try using Set tag instead of Action tag

<s:set var="mainController" value="%{'indexController'}" />   
<s:action name="%{#mainController}!loadData" executeResult="false" />

or in alternative

<s:set var="mainController" value="%{'indexController!loadData'}" />
<s:action name="%{#mainController}" executeResult="false" />

or

<c:set var="mainController" value="indexController" scope="request"/>
<s:action name="%{#request.mainController}!loadData" executeResult="false" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM