Struts <s:submit> and Struts-jquery <sj:submit> will not work in same form?

久未见 提交于 2019-12-11 14:04:34

问题


Do Struts tags <s:submit> and <sj:submit> work on same form? I have already Struts buttons <s:submit>, but now I have added <sj:submit>. So, Struts2-jQuery plugin button is working good, but Struts <s:submit> is not working.

<head>
<sj:head/>
</head>
<s:form id="myForm" action="part!list">
   <s:submit  action="part" method="list" />
</s:form>
<sj:submit targets="result" formId="myform"/>

Please clarify ...


回答1:


<s:submit> works with the form if it's inside the body of the <s:form> or <form> tag. To make it work properly use the action attribute to map the form to the action. You could also use <s:url> to build the url used in the action attribute of the form that correctly builds url even with parameters. But if you map the action in the <s:submit> tag then you have to use only one attribute action or method. These are special parameters used by the action mapper. In the first case form action will be overridden, in the second case the action method overridden. It means that the attributes action and method in the <submit> tag only used to override the default form action mapping. It's rarely used, requires DMI, if you have multiple buttons that have different methods consider to use the method attribute to override the form action mapping.

EDIT:

Example

<head>
   <sj:head/>
</head>
<s:url var="myUrl" action="part" method="list"/>
<s:form id="myForm" action="%{#myUrl}" method="POST">
   <s:submit  action="part2" />
   <s:submit  method="list2" />
   <s:submit />
</s:form>

<sj:submit targets="result" formId="myForm"/>

the above s:submit in the first case use actin named part2 to submit to, the second action name part and method list2, the third is default action name part and method list Ajax calls like the third case.

If your action is mapped on the method list, then you could simplify the url via

<s:url var="myUrl" action="part"/>


来源:https://stackoverflow.com/questions/17454151/struts-ssubmit-and-struts-jquery-sjsubmit-will-not-work-in-same-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!