Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Problem while passing values to action class from radio button
April 8, 2013 2:37 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I am having a jsp form where I have to mark attendance for each employee and store the results in the database. My jsp snippet for marking attendance is as follows:

<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>


And I use the following functions to mark the attendance:
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");
}



The problem that I am facing is that whatever attendance I mark for the first employee (Present/Absent) the same is stored for the other employees. The error I think is in the above for loop which I have italicized. How should I rectify this code such that for each employee the correct attendance status is stored?
Masroor Khan
RE: Problem while passing values to action class from radio button
April 8, 2013 4:31 AM
Answer

Masroor Khan

Rank: Regular Member

Posts: 119

Join Date: September 9, 2008

Recent Posts

Hi,

String attendanceValue = getAttendanceValue(areq);

you should get attendanceValue inside for loop by using i value.


Regards,

Masroor Khan
Seeya S Kudtarker
RE: Problem while passing values to action class from radio button
April 8, 2013 9:13 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Mansoor,
Thanks for the reply.
I tried the following by putting String attendanceValue = getAttendanceValue(areq); in the loop but it still gives me the same results. i.e. the value entered for the first employee (P/A) becomes the value for the other employees too.

int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();

for (int i = 0; i < totalEmployees; i++) {

String attendanceValue = getAttendanceValue(areq);
long attPKey = CounterLocalServiceUtil.increment(Employee.class.getName());

Attendance newAttendanceInstance = new AttendanceImpl();
newAttendanceInstance.setAttId(attPKey);
newAttendanceInstance.setAttStatus(attendanceValue);
AttendanceLocalServiceUtil.addAttendance(newAttendanceInstance);
}
}

Seeya