1

Is it possible to do something like this?

<s:form action="formAction1" namespace="/form1">
  <s:form action="formAction2" namespace="/form2">
    <s:textfield name="user"/>
    <s:password name="pwd" />
    <s:submit name="sub1" value="start1">
    <s:submit name="sub2" value="start2">
  </s:form>
</s:form>     

i.e. if I click start1 button, then formAction1 will be submitted, else when start2 is clicked, then formAction2 will be submitted. Actually I want to have 2 different actions on 2 different buttons in a single form.

I don't want to use url <s:url> tag.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Abhishek Raj
  • 109
  • 3
  • 10

2 Answers2

2

No, it's not possible in HTML, nor in Struts2. You should not have nested forms, but you can use several forms on the page.

<s:form>
 <s:textfield name="user"/>
 <s:password name="pwd" />
 <s:submit name="sub1" value="start1" action="formAction1">
 <s:submit name="sub2" value="start2" action="formAction2">
</s:form>

Also see How to align two submit buttons?. There's also information how to configure Struts2 to use action prefix.

Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • @AbhishekRaj If this answer helped you to solve your problem you should mark it as accepted. If you have a question see [About](http://stackoverflow.com/about) page. – Roman C May 25 '14 at 10:32
1

It is not possible as you have shown in your code; but you can have a one form with multiple buttons & different action can be perform on each button.

you can achieve it by using following code

<s:form method="post" action="mySubmitAction">
    // your form fields
    <s:submit value="Submit"/>
    <s:submit value="Clear" action="myClearAction"/>
</form>

Here if you click on first button mySubmitAction will be called.

If you click on second button myClearAction will be called(as we have provided action attribute in second button, instead of mySubmitAction action myClearAction action will be called).

You can access all the form field in both actions.

Hope this will help you.

Pravin Varpe
  • 188
  • 12