2. use indexed tag
DONE! Struts controller does the magic. The multi row is basis for doing master detail and many to many on the screen. Most pages need indexed (mutlirow, M/D, etc.) forms processing.
Source Ex:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/basicportal_07/src/basicWebLib/org/commons/DAO/BaseBeanImpl.java
This is a "base" bean, and it implements collection. See the iterator adapter in source above.
Struts sees this bean as a "collection" (but is's a bean) and it auto sets all the properties. You do nothing in action, etc., other than set up your base bean as a collection like above. Base, as in other beans extend this class. This means no code needed in action or concreate beans to handle multi row, just some code to set up bus. M/d processing.
Than your JSP is same as before, you just use indexed property as so:
<%@ tag lib uri="struts/html" prefix="html" %>
<%@ taglib uri="struts/logic" prefix="logic" %>
<%@ taglib uri="jstl/c" prefix="c" %>
<html>
<head>
<link rel=stylesheet type="text/css" href="css/default.css">
<html:form action="/myconcreateaction?Dispatch=Save">
<table>
<logic:iterate name="myFormBean" id="row">
<tr>
<td>FieldName:</td>
<td><html:text name="row" indexed="true" property="fieldName"/></td>
</tr>
</logic:iterate>
</table>
<html:submit property="submit" value="Save" />
</html:form>
</body>
</html>
For more.... come to my "1 day best practice Struts" class.
http://www.basebeans.com/do/classReservation
money back if you don't like. You'll learn at least 10 more cool things, but some Struts is a pre-req., I do not do intro to Struts.
hth, .V
(voted best instructor as per JDJ)
Brad Balmer wrote:
I was looking on the basicPortal site for the example, but couldn't find
it. Could you give a direct link?
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED]] On Behalf Of V. Cekvenich
Sent: Thursday, December 12, 2002 6:23 AM
To: [EMAIL PROTECTED]
Subject: Re: Processing multiple records all at once
This is good.
However.... a bit much copying. Also, quite a few forms could have multi
row processing or master/detail processing. One does not want to to it over and over; if you do OO, you could create a basebean that does this in the ancestor, by having your formbean implement a collection, as in basicPortal.com open source example.
.V
Max Cooper wrote:
Brad, I have written some pages/actions that do what you describe here. Ibelievethat one way to go would be to use nested properties, but I haven'ttriedthat yet, so I am not sure how to do it. The solution I used was tocreatean ActionForm for the page that has arrays for each field from therows.Something like this (generic example -- replace rowId and rowProperty1withyour real row properties): public class RowsForm extends ActionForm { private String[] rowId; private String[] rowProperty1; public String[] getRowId() { return rowId; } public void setRowId(String[] rowId) { this.rowId = rowId; } public String[] getRowProperty1() { return rowProperty1; } public void setRowProperty1(String[] rowProperty1) { this.rowProperty1 = rowProperty1; } } The properties are arrays to receive values from each row in the datasetwhen you submit the form. For iterating through the data, we added amethodthat would return a Collection of objects, where each represents asinglerow. Something like this: public class RowForm extends ActionForm { // this could also be aplain-oldJavaBean, too private String id; private String property1; // getters and setters for the id and property1 } // add this method to RowsForm public Collection getRows() { Collection rows = new ArrayList(); final int size = rowId.length; for (int i = 0; i < size; i++) { RowForm row = new RowForm(); row.setId(rowId[i]); row.setProperty1(rowProperty1[i]); rows.add(row); } return rows; } So, that setup will allow you to get the data out of the form afterthe usersubmits their changes (by calling RowsForm.getRows()). You will getdata foreach row, so you still need to decide which rows were changed, andwhichones the user simply left alone. As for getting the data into the form and displaying it on the page,youcould add another method like populateForm(Vector rowData) to copy thedatato the arrays like this: // another method in RowsForm public void populateForm(Vector rowData) { // get the Vector size final int size = rowData.size(); // initialize the arrays rowId = new String[size]; rowProperty1 = new String[size]; // copy the data from the objects in the Vector into the arrays Vector rowData = new Vector(); final int size = rowData.size(); Enumeration enum = rowData.elements(); for (int i = 0; i < size; i++) { Data element = (Data) enum.nextElement(); rowId[i] = String.valueOf(element.getId()); rowProperty1[i] = element.getProperty1(); } } However, it might be a bit wasteful to copy all the data into thearrays ifyou are going to call getRows() to turn them back into a Collection of objects so that you can use the <logic:iterate> tag to display them intheJSP. If you can get the data into a Collection instead of a Vector (oris aVector a Collection these days?), you can just have a singleCollectionproperty on RowsForm that you set in the action, and the JSP will callthegetter to get the Collection to iterate over. The JSP to iterate overtheCollection and write out the rows might look something like this: <table> <tr> <th>id</th> <th>property1</th> </tr> <logic:iterate name="rowsForm" property="rows" id="row" type="com.yada.yada.yada.RowForm" scope="request"> <tr> <td> <%-- write the id as text for display, and also as a hidden fieldforsubmittal --%> <bean:write name="row" property="id" /> <html:hidden name="row" property="id" /> </td> <td> <html:text name="row" property="property1" /> </td> </tr> </logic:iterate> </table> Your Action will get the populated RowsForm on the submit, and you cancallRowsForm.getRows() to get a Collection of RowForm objects to workwith.-Max ----- Original Message ----- From: "Brad Balmer" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, December 11, 2002 5:44 PM Subject: Processing multiple records all at onceI've searched the internet and different news groups for an answer tothisquestion, but have yet to find something that matches what I'm tryingtodo.I have an application that reads records from a table and creates an instance of a bean for each row. Therefore, when I return from my DBcall,I have a Vector of beans representing the data. I need to display all of this on one jsp form, letting the user havetheability to update any of the fields in any of the records and click aUpdatebutton, which will send ALL of the data back to the Action class to be processed. I have done this before (not using Struts), but we haveswitchedour Architecture and need to re-implement. Any help would be GREATLY appreciated. _________________________________________________________________ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus -- To unsubscribe, e-mail:<mailto:[EMAIL PROTECTED]>For additional commands, e-mail:<mailto:[EMAIL PROTECTED]>-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

