Aaron,

I have a sample that does something similar to what I think you are asking.  
I did not use a single submit.  I used multiple submits and sent them to the 
same Action class.

Here is the full JSP page from the application I developed for Wrox Pro JSP 
2nd edition chapter 21 on Struts.

See comments added in the JSP page and the comments at the end of the page.

---- start: shoppingcart.jsp --------------
<%@ page language="java"
  import="java.util.Collection,
          java.util.Iterator,
          java.util.Locale,
          java.util.HashMap,
          com.wrox.pjsp2.struts.common.CartItem,
          com.wrox.pjsp2.struts.common.CD,
          com.wrox.pjsp2.struts.common.Constants,
          com.wrox.pjsp2.struts.common.ShoppingCart,
          org.apache.struts.action.Action
          "
%>
<%@ taglib uri="/app" prefix="app" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<app:checkLogon/>
<%--
        exposes the shopping cart in the pageContext with id=shoppingCart,
        id does not work with rtexprvalue.
<jsp:useBean id="shoppingCart" 
type="com.wrox.pjsp2.struts.common.ShoppingCart"
        scope="session"/>
        Can use the struts tag to expose the cart
--%>
<bean:define id="shoppingCart" name="shoppingCart" scope="session"/>
<html:html locale="true">
<head>
  <title><bean:message key="shoppingcart.title" /></title>
</head>
<body>
<html:base/>
<%@ include file="header.html" %>
<p></p>
<table cellspacing="2" cellpadding="2" border="0">
  <tr>
    <td width="120">&nbsp;</td>
    <td align="center">
      <h1><bean:message key="shoppingcart.title" /></h1>
    </td>
  </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td align="left">
      <bean:message key="shoppingcart.instructions" />
    </td>
  </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td valign="top">
      <p></p>
      <table cellspacing="2" cellpadding="2" border="1">
        <tr bgcolor="#B0E0E6">
          <th><bean:message key="tableheading.artist" /></th>
          <th><bean:message key="tableheading.title" /></th>
          <th><bean:message key="tableheading.unitPrice" /></th>
          <th><bean:message key="tableheading.quantity" /></th>
          <th><bean:message key="tableheading.itemTotal" /></th>
        </tr>
<%
  int num = 0;
  String SLATE = "#C0C0C0";
  String WHITE = "#FFFFFF";
  String bgColor = null;
%>
<!--
   Here I'm iterating over the items in the shopping cart.  I'm creating a 
form for each item with its own submit button.
-->
<logic:iterate id="cartItem"
             type="com.wrox.pjsp2.struts.common.CartItem"
             name="shoppingCart"
         property="cartItems">
<%
  num++;
  if((num % 2) == 0) {
    bgColor = SLATE;
  } else {
    bgColor = WHITE;
  }
%>
  <bean:define id="cd" name="cartItem" property="cd" 
type="com.wrox.pjsp2.struts.common.CD"/>
        <tr bgcolor="<%= bgColor %>">
            <td><jsp:getProperty name="cd" property="artist"/></td>
            <td><jsp:getProperty name="cd" property="titleName"/></td>
            <td><jsp:getProperty name="cd" property="price"/></td>
            <td valign="middle">
              <!-- each form has the same action.  The action class knows 
what row it is by using the TITLE_ID as a hidden property. -->
              <html:form action="/checkout.do">
                <html:hidden property="action" value="update" />
                <bean:define id="titleId" name="cd" property="titleId"/>
                <html:hidden property="<%= Constants.TITLE_ID %>"
                                value="<%= String.valueOf(titleId) %>" />
                <table cellspacing="2" cellpadding="2" border="0">
                  <tr>
                      <td>
                        <bean:define id="quantity" name="cartItem" 
property="quantity"/>
                        <html:text property="quantity"
                                      value="<%= String.valueOf(quantity) 
%>"
                                       size="5" maxlength="5"/>
                      </td>
                      <td>
                        <html:submit>
                           <bean:message key="button.update"/>
                        </html:submit>
                      </td>
                  </tr>
                </table>
              </html:form>
            </td>
            <td><jsp:getProperty name="cartItem" property="total"/></td>
        </tr>

</logic:iterate>
        <tr bgcolor="#B0E0E6">
            <td colspan="4" align="right"><bean:message 
key="tableheading.total" /></td>
            <td><b>
                                <jsp:getProperty name="shoppingCart" property="total"/>
                                </b>
                        </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
  <td>&nbsp;</td>
  <td align="center">
    <html:form action="/order.do">
      <html:hidden property="action" value="createOrder" />
        <html:submit>
           <bean:message key="button.createOrder"/>
        </html:submit>
    </html:form>
  </td>
  </tr>
</table>
<%
  boolean omitCheckoutLink = true;
%>
<%@ include file="footer.jsp"%>
</body>
</html:html>
---- end:   shoppingcart.jsp --------------

I provided the ability for the user to change the quantity of the shopping 
cart item.  I would assume that you would want the ability to change the 
salary.  You could accomplish this in much the same way by making the 
employee name or id (assuming you have access to an id) and the salary both 
hidden parameters for each individual form that represents a row.

Granted this may not be the most elegant solution, but I believe that it is 
a simple solution.  Sometimes simple is not elegant! :-)

Hope this helps...
If I can every get NewParticles to update my source code you will be able to 
download the latest edition from the http://www.newparticles.com/struts web 
site.  The latest version is similar to new one, but I've started using the 
commons packages and I've clean up the JSP pages to use less scriptlet 
coding.

Enjoy,
Steve

>From: "Rustad, Aaron" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: 'Struts Users Mailing List' <[EMAIL PROTECTED]>
>Subject: suggestions for multiple entries - One submit?
>Date: Mon, 11 Feb 2002 10:07:22 -0700
>
>Hello everyone.
>
>I have a JSP page that allows the user to entry multiple rows of
>information, for example:
>
>Employee       Salary
>--------       -------
>Aaron          20000
>Chris          30000
>Jack           40000
>
>
>Since these rows would be dynamically generated, they would have to submit
>to the same properties of
>one form (or at least that would be my understanding).
>
>Anyone have some insight as to the best way to achieve this?
>
>Thanks!
>Aaron.
>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>
>




_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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

Reply via email to