File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to submit multiple records in one trip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to submit multiple records in one trip" Watch "How to submit multiple records in one trip" New topic

How to submit multiple records in one trip

Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
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.
poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
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

Joined: Jan 23, 2002
Posts: 145
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 ]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.

SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Sandeep Ghosh
Ranch Hand

Joined: Jan 23, 2002
Posts: 145
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" %>
<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();
<html:form action="/test/">
<table id="table1">
<td><html:text property="userName" /></td>
<td><html:button value="Add New" onclick1="return button1_onclick()"
3. In my action class I am getting all the entered values.
If anybody knows more efficent way plz let me know.
I agree. Here's the link:
subject: How to submit multiple records in one trip
It's not a secret anymore!