Hi Eric

I do not know if what I can provide will help.  I have only been using
Struts for a month.  Your post was almost identical to one I was about to
send so I was hoping to see some replies to yours.

Anyhow what I have so far is this (an Edit):

[I refer to a Distribution Channel entity which has a Name and Bank Account.
Name is the PK of this entity]

I have a jsp page called Customer Maintenance.
It lists the customers in a table like:

DISTRIBUTION CHANNEL NAME               ACTION
Bob                                             Edit
Bill                                            Edit
Sam                                             Edit

The Edit button is an Image and I am using Struts ImageButtonBean as
outlined in Ted's Strus tips at www.husted.com.

What I have just got to *that works* is this:

<logic:iterate id="channel" name="DistributionChannelMaintenanceBean"
property="distributionChannels">
        <tr><html:form action="/DistributionChannelMaintenance" >
                <td align="left">
                        <bean:write name="channel" property="name"
filter="true"/>
                </td>
                <td align="center">
                        <html:image
src="http://localhost/ims/images/goButton.gif"; property="editButton" />
                </td>
                <html:hidden name="channel" property="name" />
        </html:form></tr>
</logic:iterate>

The DistributionChannelMaintenanceBean has a collection of the Distribution
Channels that I iterate thru writing my table.  I am also creating a <form>
around each "record" with the hidden tag storing the value of the
distribution name.

When I submit the form with Edit button, my Action class gets the
Distribution Name value and sets a session attribute
(distributionChannelName) and forwards to my edit page (which will also do
create/add later).

String distributionChannelName = request.getParameter("name");
request.getSession().setAttribute("distributionChannelName",
distributionChannelName);
return mapping.findForward(FORWARD_edit);

The FORWARD_edit ends up going to the
path="/EditDistributionChannel.do?action=Edit" 

In the Action class I do:

String action = request.getParameter("action");

if ("Edit".equals(action))
{
        String distributionChannelName = (String)
request.getSession().getAttribute("distributionChannelName");
        DistributionChannel distributionChannel =
DistChannelManager.get().getDistributionChannel(distributionChannelName);
        editDistributionChannelBean.setName(distributionChannel.getName());
        
editDistributionChannelBean.setCmaBankAccount(distributionChannel.getCmaBank
Account());
        
editDistributionChannelBean.setProducts(distributionChannel.getAllProducts()
);
        return mapping.findForward(FORWARD_create);
}



So that is where I am currently.  I may have done some *ugly* things at this
stage because this is a change from having an Edit page where a selector box
displayed the distribution channels to edit and the Create came from another
page.  Create will (soon) some from my new Distribution Channel maintenance
page.


I guess where this may help you is in using a form for each record.

Anyhow if I can be of any help let me know and if you find anything that you
think I would find helpful please let me know.

Cheers
Shane





-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 28 May 2003 3:02 p.m.
To: [EMAIL PROTECTED]
Subject: Basic CRUD

I am putting together a simple web app that performs CRUD operations on a
database table.  The web app consists of 1 jsp page which handles all CRUD
actions.  The first part of the page contains a form with 2 fields and
'create' and 'retrieve' buttons.  Both these functions work fine.  When a
'retrieve' (select id,field1,field2 from table1) is done, a table is
rendered with the resultset on the same page.  For each record of the
recordset, there exists an 'update' and 'delete' button.  The problem is
how do I tell my action class which record to act on?

class MyFormBean extends ActionForm {
   private MyBean myBean;
   private ArrayList myBeanList;
}

class MyBean {
   private Long id;
   private String field1;
   private String field2;
}


The idea is to manage this 1 particular db table from a single view with a
single action class extended from LookupDispatchAction.  I've tried
several ways with no success.  I've tried using 1 form that includes
everything.  I've tried using a form for each record.  I've tried using
the nested taglib.  I believe this is view/jsp/taglib problem since the
actions are firing correctly.  How can I populate 'myBean' with the data
of the corresponding record from which the 'update' or 'delete' buttons
were clicked?

I prefer not to use checkboxes with a global 'update' and 'delete' button.
 I prefer not to use javascript (I'm not a big fan of this scripting
language and only use it when absolutely necessary, which is rare).  I
prefer not to go to a second page to "edit".

Can this be done exclusively within Struts?

Thanks in advance.
-Eric


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to