• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to submit multiple records in one trip

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends,
I need to submit multiple records to action class from jsp in one trip. In my jsp I have 4 textfield and 1 button. Button had this text "Add new record". Pressing button will add another set of textfields and button . User can enter n records till he presses submit button. Once he presses submit all the records entered by user will go to action class. I have a bean with 4 fields ( one for each textfield) . Could anybody give some tips how to solve this problem.
Thanks in adv.
Sonu
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If you are generating same textboxes each time when the user request for new record , then index those textboxes . for that indexed textboxes create a list in your form bean
 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I have managed to do that. I turns out to be much simpler than I thought. I can't manage to submit my codes now. Giving some wierd reason
[ April 28, 2005: Message edited by: Nataraj Ramesh ]
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may use the same name or indexed property to handle *multiple* fields that are of the same type. And thus, you dont need to care about how many textfields have been submitted.
You can take the multiple checkbox as an example.
Nick
 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have done
1.In my ActionForm my properties are now array i.e username[]
2.In JSP I have this one
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html>
<head>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function button1_onclick()
{
var row = table1.insertRow();
var cell =row.insertCell();
cell.innerHTML ="<INPUT type='text' name='userName'>";
var cell = row.insertCell();
}
//-->
</SCRIPT>
</head>
<html:form action="/test/newuserrecord.do">
<table id="table1">
<tr>
<td><html:text property="userName" /></td>
<td><html:button value="Add New" onclick1="return button1_onclick()"
property="hello"/></td>
</tr>
</table>
<html:submit/>
</html:form>
</html:html>
3. In my action class I am getting all the entered values.
If anybody knows more efficent way plz let me know.
Sonu
 
reply
    Bookmark Topic Watch Topic
  • New Topic