• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help! Form to update multiple records upon save

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! Hoping someone can help:

I have a JSP containing a checklist -type form where I'm trying to present a list of employees and two checkboxes beside each name, where the checkboxes correspond to employee.check1 (boolean) and employee.check2 (boolean). I want to be able to scroll down the list of employees and check off box 1 and/or box 2 for each employee, hit Save (once) at the bottom and have it update each employee's record and set check1 and check2 accordingly. I have a viewChecklist.jsp and an editChecklist.jsp. Here is the display only list on viewChecklist.jsp:

<table border="0" width="400">
<tr>
<td><b>Last, First</b></td>
<td><b>ID</b></td>
<td><b>-1-</b></td>
<td><b>-2-</b></td>
</tr>
<c:forEach items="${employeesForChecklist}" var="employee">
<%-- nitrox:varType="com.xyz.forms.EmployeeForm" --%>
<tr>
<td><c:out value="${employee.lastName}"/>, <c:out value="${employee.firstName}"/></td>
<td><c:out value="${employee.idNumber}"/></td>
<td><html:checkbox disabled="true" name="employee" property="check1"/></td>
<td><html:checkbox disabled="true" name="employee" property="check2"/></td>
</tr>
</c:forEach>
</table>

On the editChecklist.jsp, I want something similar but with the checkboxes enabled. assuming I may need to switch from forEach (which iterates my session variable employeesForChecklist) to a logic:iterate ? The app uses Nitrox but not sure I need to use that here. I'm rusty with this stuff, creating a row index and how to build the array of employee IDs that need updating is just eluding me. Tips? Suggestions? Code samples? thanks in advance!!!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to do this, you will need to use "indexed properties". Please refer to question 6 of our FAQ for more information on indexed properties along with a working example.
 
Greg C Robinson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!!
 
Greg C Robinson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'm real close here. Using that FAQ link - which was VERY helpful, thanks! - I was able to get my checklist utility working. However, I have one minor quirk. The first time I ran it, all checkboxes were empty/false. Which was expected. I then went down and selectively checked a few records and they all set properly. Nice. However, UNchecking those checkboxes does not set the boolean back to false. When I step through the debugger, I see the iteration's row is showing TRUE for those checkboxes. My thought was that it was seeing null and I might need to explicity check for null and if so, set to false - but I cannot see a null coming in. All I see is true. My code is very closesly modeled after what's found in that FAQ page, so I won't paste it all here. Any thoughts on what I might need to add?

Here is my iteration on the JSP:

<logic:iterate id="employeeForm" name="checklistItemForm" property="employeeList">
<html:hidden name="employeeForm" property="employeeID" indexed="true" />
<tr>
<td><bean:write name="employeeForm" property="lastName" />,
<bean:write name="employeeForm" property="firstName" /></td>
<td><bean:write name="employeeForm" property="crdNumber" /></td>
<td><html:checkbox name="employeeForm" property="check1" indexed="true" /></td>
<td><html:checkbox name="employeeForm" property="check2" indexed="true" /></td>
<td><html:checkbox name="employeeForm" property="check3" indexed="true" /></td>
</tr>
</logic:iterate>

here is checklistItemForm.getEmployeeForm:

public EmployeeForm getEmployeeForm(int index)
{
// make sure that orderList is not null
if(this.employeeList == null)
{
this.employeeList = new ArrayList();
}

// indexes do not come in order, populate empty spots
while(index >= this.employeeList.size())
{
this.employeeList.add(new EmployeeForm());
}

// return the requested item
return (EmployeeForm) employeeList.get(index);
}

Here is the relevant portion of the action called upon save/submit:

List employeeList = checklistForm.getEmployeeList();

try {

IEmployeeManager employeeManager = (IEmployeeManager)getServiceLocator().getEmployeeManager();

//employeeManager.updateChecklistValues(employeeList);

for(Iterator employeeIter = employeeList.iterator(); employeeIter.hasNext() ;)
{
EmployeeForm employeeRow = (EmployeeForm) employeeIter.next();
String empIDkey = employeeRow.getEmployeeID();
EmployeeImpl employee = (EmployeeImpl)employeeManager.findEmployeeByID(empIDkey);
if(employee != null)
{
employee.setCheck1(employeeRow.isCheck1());
employee.setCheck2(employeeRow.isCheck2());
employee.setCheck3(employeeRow.isCheck3());

employeeManager.saveEmployee(employee);
failed = false;
}
}
}

The red text is where I'm scratching my head. It works going false to true but I can't UNcheck the boxes to get back to false.

Help? thanks!
 
Greg C Robinson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One additional note to add: on my EmployeeForm, I do have a reset method where my boolean values get explicitly set to false. However, while this does get called and works fine for individual employee record updates, that reset method is NOT getting when using this checklist. the iteration is a collection of EmployeeForm beans, but the reset does not get referenced. I do not currently have a reset method in my ChecklistItemForm.

Hoping someone can help! thanks...
 
reply
    Bookmark Topic Watch Topic
  • New Topic