• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending collection to Action  RSS feed

Sreek Gupta
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a jsp as follows:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>


<h3>Example Page</h3>


<html:form action="dept.do">
Dept No: <html:select property="deptNumber">
<html ption value="100">100</html ption>
<html ption value="200">200</html ption>
<html:submit property="whichButton"> <bean:message key="button.fetch"/></html:submit>

<logic resent name="empDetailTable" scope="session">

<% java.util.ArrayList lst = (java.util.ArrayList) session.getAttribute("empDetailTable");

<html:form action="dept.do">
<table border=1>
<td class="txtBld headerClr" width="12%" height="26">First Name</td>
<td class="txtBld headerClr" width="12%" height="26">Middle Name</td>
<td class="txtBld headerClr" width="12%" height="26">Last Name</td>
<td class="txtBld headerClr" width="11%" height="26">Induction Id</td>
<td class="txtBld headerClr" width="9%" height="26">Gender</td>
<td class="txtBld headerClr" width="8%" height="26">Attendance</td>

<logic:iterate id="emp" name="empDetailTable">
<td><html:text property="firstName" value="<%=((employee.DeptFetchBean)emp).getFirstName()%>"/></td>
<td><html:text property="lastName" value="<%=((employee.DeptFetchBean)emp).getLastName()%>"/></td>
<html:submit property="whichButton"> <bean:message key="button.save"/></html:submit>
</logic resent>


When i click on Fetch button, I need to get all the employess belonging to a particular department from database, And i have show them up in a table in the same page. This part i have done.
Once i get the employees i should be able to edit any employee details and click on Save button should save these details in the database again.
Since each department will have many employees, when i click on Save button how can i propagate all the updated entries further (to my action servlet)?
It would be helpful if you can provide me some example code for this scenario.

Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The firs thing you'd need to do is create an ActionForm that looks like this:

You would then use indexed properties for your <html:text> tags within the iterate loop. If you do this, Struts will populate the form bean for each item in the list if changes are made.

Your JSP code would look something like this:

<logic:iterate id="employee" name="myActionForm" property="employees>
<html:text name="employee" property="firstName" indexed="true" />
<html:text name="employee" property="lastName" indexed="true" />

Note: you do not have to code a value attribute. Struts automatically gets and displays the value.

For more information on how to used indexed properties, see the following links:


[ July 24, 2006: Message edited by: Merrill Higginson ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!