Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Passing value with multiple actions in same form

 
Nepean Robert
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am new to JSP/Struts. I really need your help on how to pass values in a form with multiple actions. Please help out.

Here is the sample code.
<html:form action="someAction" method="post">
<table>
<tr>
<td><html:select property="factoryId">
<htmlption...>
</td>
</tr>
<tr><td><html:link page="/actions/../actionOne.do"></td></tr>
<tr><td><html:link page="/actions/../actionTwo.do"></td></tr>
</table>
</html:form>

My question: how to pass factoryId to servlet (Struts action)?
Many thanks.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

You should open this topic in the Struts forum.

If you are using Struts 1.x, you need to use struts 'form's. If you are using Struts 2, you can make a factoryId instance variable in the action class and it will be populated.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Report post to moderator
For multiple actions, usually, in Struts, you have to do an extra effort to handle multiple actions in one form.

For example, you have 2 buttons, say, one to Save and another to Delete. You can put onClick javascript function on both buttons. Both will call the same javascript function when clicked, for example processClick(). However, they will pass a parameter. Save will call processClick('save'), and Delete will call processClick('delete').

Inside processClick, it will be like:

processClick(clicked){
if (clicked=='save'){
....forms[0].action='/asdf/asdf/save.do';}
else{
....forms[0].action='/asdf/asdf/delete.do';}

....forms[0].submit;
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
    Bookmark Topic Watch Topic
  • New Topic