我有一个 jsp 表单,我必须在其中标记每个员工的出勤率并将结果存储在数据库中。我标记出勤的jsp片段如下:
<portlet:defineObjects />
<%
List<Employee> EmployeeAttendanceDetails = MISPortalActionUtil.getEmployeeData();
%>
<portlet:renderURL var="viewMarkAttendanceURL"/>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>mark attendance</title>
</head>
<body>
Mark Attendance for Today:
<%= new java.util.Date() %>
<portlet:actionURL name="updateDailyAttendance" var="updateDailyAttendanceURL" />
**<aui:form name="updateDailyAttendance" action="<%=updateDailyAttendanceURL.toString()%>" method="post" >
<portlet:renderURL var="viewEmployeeDataURL"/>
<liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">
<liferay-ui:search-container-results total="<%= EmployeeAttendanceDetails .size() %>"
results="<%= ListUtil.subList(EmployeeAttendanceDetails , searchContainer.getStart(), searchContainer.getEnd()) %>" />
<liferay-ui:search-container-row modelVar="search"
className="com.test.mis.portal.model.Employee">
<liferay-ui:search-container-column-text name='Employee Name' value='<%=String.valueOf(search.getEmpFname()) + " " + String.valueOf(search.getEmpLname())%>' href="" />
<liferay-ui:search-container-column-text name='Employee Id' value='<%=String.valueOf(search.getEmpId())%>' href="" />
<liferay-ui:search-container-column-text name = "Attendance Status" >
<label>Present</label><input type = "radio" name ='updateattendance + <%=String.valueOf(search.getEmpId())%>' value = "present" />
<label>Absent</label><input type = "radio" name= 'updateattendance + <%=String.valueOf(search.getEmpId())%>' value = "absent"/>
</liferay-ui:search-container-column-text>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer %>" paginate="<%=true %>" />
</liferay-ui:search-container>
<input type = "submit" value = "Update"/>
</aui:form>**
我使用以下函数来标记出勤: public void updateDailyAttendance(ActionRequest areq, ActionResponse aRes) throws Exception{
int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();
String attendanceValue = getAttendanceValue(areq);
***for (int i = 0; i < totalEmployees; i++) {
long attPKey = CounterLocalServiceUtil.increment(Employee.class.getName());
Attendance newAttendanceInstance = new AttendanceImpl();
newAttendanceInstance.setAttId(attPKey);
newAttendanceInstance.setAttStatus(attendanceValue);
AttendanceLocalServiceUtil.addAttendance(newAttendanceInstance);
}***
}
private String getAttendanceValue(ActionRequest areq) {
Enumeration parameters = areq.getParameterNames();
while (parameters.hasMoreElements()) {
String parameterName = parameters.nextElement().toString();
if (parameterName.startsWith("updateattendance")) {
return areq.getParameter(parameterName);
}
}
throw new IllegalStateException("Parameter updateattendance is not found");
}
我面临的问题是,无论我为第一位员工(在场/缺席)标记的出勤情况,都会为其他员工存储相同的出勤率。我认为错误出现在上面的 for 循环中,我用斜体表示。我应该如何更正此代码,以便为每个员工存储正确的出勤状态?