0

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, Struts 2 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"/>
Roman C
  • 49,761
  • 33
  • 66
  • 176
user2543737
  • 41
  • 3
  • 7

1 Answers1

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"/>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Okay , what about outside form.. – user2543737 Jul 03 '13 at 18:08
  • Could you please give me small example for method overridden using url. – user2543737 Jul 03 '13 at 18:13
  • 1
    `sj:submit` works slightly different than s:submit and has `formId` attribute, so it can find the form which is submitting and serialize it to set `formData` in Ajax post. – Roman C Jul 03 '13 at 18:29
  • @user2543737 I have updated the answer, and if you produce urls like `action!method` it could use the `method` other than mapped to the `action`. Notice if action is not mapped to the method then it's treated `execute` method is mapped instead. – Roman C Jul 03 '13 at 18:51