I'm trying to point a button in my form tag to a different action/action class than the form but it won't work. I read in another thread that this is due to a bug in Struts 2 and that struts.mapper.action.prefix.enabled"="true"
should be set, so I did it but it's still the same.
I can use a different action pointing to a different method of the same action class that the form is using but when I try specifying a different action class it doesn't work.
This works,
(jsp)
<s:form action="print">
<s:iterator value="itemList">
<s:radio theme="simple" name="item" list="#{id:name}" />
</s:iterator>
<div id="functionButtons">
<s:submit key="button.submit" />
<s:submit action="cancel" key="button.cancel"/>
</div>
</s:form>
(struts.xml
)
<constant name="struts.mapper.action.prefix.enabled" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
...
<action name="print" class="...PrintItem" method="perform" >
<result name="success">/successJSP.jsp</result>
</action>
<action name="cancel" class="...PrintItem" method="cancel" >
<result name="CANCEL" type="redirectAction">homePage</result>
</action>
(action)
public class PrintItem extends BaseAction {
@Override
public String perform() throws Exception {
doPrintLogic();
return SUCCESS;
}
public String cancel(){
return "CANCEL";
}
}
but if I change "cancel" action mapping in struts.xml
to
<action name="cancel" class="...CancelFormAction" method="perform" >
<result name="CANCEL" type="redirectAction">trnsfr</result>
</action>
it doesn't
Is that normal? Is it possible to map to a different action class from within a form that's already mapped to one?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…