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. I
believe
> that one way to go would be to use nested properties, but I haven't
tried
> that yet, so I am not sure how to do it. The solution I used was to
create
> an ActionForm for the page that has arrays for each field from the
rows.
> Something like this (generic example -- replace rowId and rowProperty1
with
> your 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 data
set
> when you submit the form. For iterating through the data, we added a
method
> that would return a Collection of objects, where each represents a
single
> row. Something like this:
> 
> public class RowForm extends ActionForm { // this could also be a
plain-old
> JavaBean, 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 after
the user
> submits their changes (by calling RowsForm.getRows()). You will get
data for
> each row, so you still need to decide which rows were changed, and
which
> ones the user simply left alone.
> 
> As for getting the data into the form and displaying it on the page,
you
> could add another method like populateForm(Vector rowData) to copy the
data
> to 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 the
arrays if
> you 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 in
the
> JSP. If you can get the data into a Collection instead of a Vector (or
is a
> Vector a Collection these days?), you can just have a single
Collection
> property on RowsForm that you set in the action, and the JSP will call
the
> getter to get the Collection to iterate over. The JSP to iterate over
the
> Collection 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 field
for
> submittal --%>
>     <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 can
call
> RowsForm.getRows() to get a Collection of RowForm objects to work
with.
> 
> -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 once
> 
> 
> 
>>I've searched the internet and different news groups for an answer to
this
>>question, but have yet to find something that matches what I'm trying
to
> 
> do.
> 
>>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 DB
> 
> call,
> 
>>I have a Vector of beans representing the data.
>>
>>I need to display all of this on one jsp form, letting the user have
the
>>ability to update any of the fields in any of the records and click a
> 
> Update
> 
>>button, 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 have
> 
> switched
> 
>>our 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]>

Reply via email to