Dynamic c: form action

Is there a way to specify a dynamic action attribute in the s:form tag in Struts2? I want something like below.

 <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> 

I know this can be achieved using javascript, but I want to avoid refactoring. I tried to achieve this using scripts, but the problem is that Struts2 tags do not accept runtime attributes . I tried even with OGNL, but that didn't help either.

+7
dynamic jsp struts2 action ognl
source share
2 answers

Use Struts2 tags to set values ​​and check status, and then use OGNL to place the action attribute.

 <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> 
+7
source share

Use the s:url tag to dynamically generate the action url.

 <s:url action="%{somePoperty}" var="myUrl"/> <s:form action="%{#myUrl}"> 

In fact, the attributes of the Struts tags do not accept not only scriptlets, but also JSTL EL expressions.

+2
source share

All Articles