动态s:表单动作

Kas*_*zar 7 jsp action struts2 dynamic ognl

有没有办法在Struts2 action中的s:form标记中指定动态属性?我想要类似下面的东西.

<c:set var="formAction" value="baseAction" />
<c:if test="${someCondition}">
     <c:set var="formAction" value="childAction" />Ac

<s:form method="post" action="${formAction}">
    <s:input....../>
    <s:select...../>
</s:form>
Run Code Online (Sandbox Code Playgroud)

我知道这可以使用javascript实现,但我想避免重构.我尝试使用scriplets实现这一点,但问题是Struts2标签不采用运行时属性.我甚至尝试使用OGNL,但它也没有帮助.

Ale*_*r M 7

使用Struts2标签设置值并检查条件,然后使用OGNL放置action属性.

<s:set var="formAction" value="'baseAction'" />
<s:if test="some_condition">
  <s:set var="formAction" value="'childAction'" />
</s:if>

<s:form method="post" action="%{#formAction}">
  <s:input....../>
  <s:select...../>
</s:form>
Run Code Online (Sandbox Code Playgroud)