Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Radio button in search container for each entry retrieved from database
March 27, 2013 6:16 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I am creating a form for marking attendance details .

I am retrieving employee information from database and displaying it using search-container

For each row which dispplays name, I have created a radio button to mark attendance status ( present/absent). code is as below:

<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="comtest.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>

<liferay-ui:search-container-column-text>
<label>Present</label><input type = "radio" name = "updateattendance" value = "present" />
<label>Absent</label><input type = "radio" name= "updateattendance" value = "absent"/>
</liferay-ui:search-container-column-text>

<!-- Get Attendance Remarks for each employee -->

<liferay-ui:search-container-column-jsp name = "Attendance Remarks" path="/admin/AttendanceDetails.jsp" align="center"/>

<!-- Get Attendance Remarks for each employee -->


</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer %>" paginate="<%=true %>" />
</liferay-ui:search-container>


<input type = "submit" value = "Update"/>
</aui:form>


When I used the above approach there was only ONE value for radio button for all the entries that was getting selected. i.e. if i marked present for first entry and went on second entry to mark presnt, the selected radio button moved to next entry to mark him present. It is becoming like a radio group.

Hence in the above code which is highlighted in bold I had done the following:

<liferay-ui:search-container-column-jsp name = "Attendance Status" path="/admin/radioButtonDisplay.jsp" align="center"/>

radioButtonDisplay.jsp is as follows:
<portlet:actionURL name="updateDailyAttendance" var="updateDailyAttendanceURL" />


<aui:form name="updateDailyAttendance" action="<%=updateDailyAttendanceURL.toString() %>" method="post" >
<label>Present</label><input type = "radio" name = "updateattendance" value = "present" />
<label>Absent</label><input type = "radio" name= "updateattendance" value = "absent"/>
</aui:form>

In this approach when I click on radio button for each employee name and then click on submit only the attendance entry of the first employee gets updated in the database. rest entries are neglected.

Any suggestion how I should approach the above problem??

Thanks!!
mohammad azaruddin
RE: Radio button in search container for each entry retrieved from database
March 27, 2013 7:05 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 439

Join Date: September 17, 2012

Recent Posts

HI
In radioButtonDisplay.jsp get the current row using

<%
ResultRow row =(ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Employee employee= (Employee) row.getObject();
long primKey = employee.getPrimaryKey();

%>

and in same page(radioButtonDisplay.jsp) you write your logic
mohammad azaruddin
RE: Radio button in search container for each entry retrieved from database
March 27, 2013 7:12 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 439

Join Date: September 17, 2012

Recent Posts

Hi
forgot to mention..use second method <liferay-ui:search-container-column-jsp name = "Attendance Status" path="/admin/radioButtonDisplay.jsp" align="center"/>

Regards
Seeya S Kudtarker
RE: Radio button in search container for each entry retrieved from database
March 27, 2013 7:14 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

mohammad azaruddin:

Thanks mohammad azaruddin for you prompt replies and your timely help you have given me everytime with my project.

The attendance that I am updating is in the attendance table. I am only using Employee table to get the name of the employee. I want to enter the attendance status in Attendance table. the column for that is attStatus.

So I guess I need to do as follows:

<%
ResultRow row =(ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Attendance att= (Attendance) row.getObject();
long primKey = Attendance.getPrimaryKey();

%>

Will this serve the purpose?

I havent tried this but will try it..

Regards

Seeya
mohammad azaruddin
RE: Radio button in search container for each entry retrieved from database
March 27, 2013 7:28 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 439

Join Date: September 17, 2012

Recent Posts

Seeya S Kudtarker:
mohammad azaruddin:

<%
ResultRow row =(ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Employee att= (Employee ) row.getObject();
long primKey = att.getPrimaryKey();// u will get primary key of selected row

%>
And when u add column jsp in search container it will add for each row in search container.And by using above lines u can get the primary key of selected row


And if u want to store attendance in one click you can use checkbox instead of column-jsp
Seeya S Kudtarker
RE: Radio button in search container for each entry retrieved from database
March 27, 2013 8:00 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Like I said I want to add the attendace status entry to the Attendance table.
So shouldn't I get the prim key of Attendance table like below?
<%
ResultRow row =(ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Attendance att= (Attendance) row.getObject();
long primKey = att.getPrimaryKey();// u will get primary key of selected row

%>

And is the logic in action class as follows ?


String updateattendance = areq.getParameter("updateattendance");


long pattKey = CounterLocalServiceUtil.increment(Employee.class.getName());


Attendance newAttendanceInstance = new AttendanceImpl();

newAttendanceInstance.setAttId(pattKey);


newAttendanceInstance.setAttStatus(updateattendance);

AttendanceLocalServiceUtil.addAttendance(newAttendanceInstance);



"updateattendance" in getParameter is the name og the radio button.
Seeya S Kudtarker
RE: Radio button in search container for each entry retrieved from database
March 28, 2013 12:29 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Here is my radio button in my form in my jsp:

<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.corpserver.mallyas.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>


<!-- Get Attendance Remarks for each employee -->

<liferay-ui:search-container-column-jsp name = "Attendance Remarks" path="/admin/AttendanceDetails.jsp" align="center"/>

<!-- Get Attendance Remarks for each employee -->


</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer %>" paginate="<%=true %>" />
</liferay-ui:search-container>


<input type = "submit" value = "Update"/>
</aui:form>


How to pass the radio button name to java class which has some code in it?
The usual way to get the value in java class is as:
String attval = request.getParameter("radiovalue") where radiovalue is the name if the radio button in my jsp.

So how do I pass it when the name of radio button has some code in it??
mohammad azaruddin
RE: Radio button in search container for each entry retrieved from database
March 28, 2013 1:33 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 439

Join Date: September 17, 2012

Recent Posts

can you share your service.xml here...i guess your database design isn't well designed.
are you storing attendance on daily basis...?
is your DB well designed to save attendance for all employees ..?
Because we are not supposed to mess with requirnment analysis and Database designemoticon
Seeya S Kudtarker
RE: Radio button in search container for each entry retrieved from database
March 28, 2013 1:37 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

hey!!
Thanks again for your quick reply.
I found the answer and I would like to share the code here in case you want to see it.


Enumeration parameters = request.getParameterNames();
while(parameters.hasMoreElements()) {
String parameterName = parameters.nextElement().toString();
if(parameterName.startsWith("updateattendance")){
String parameterValue = request.getParameter(parameterName);
// parameterValue is value of radio button parameter
}
}

It was simple, isn't it? emoticon

Regards!!
Seeya S Kudtarker
RE: Radio button in search container for each entry retrieved from database
March 28, 2013 1:48 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

As you advised yesterday I ws using a sepaarte jsp for the display of radio attendance.
By using radio buttons in search-container as:
<input type = "radio" name = 'updateattendance + <%=String.valueOf(search.getEmpId())%>'/>
simplifies a lot.
using 'updateattendance + <%=String.valueOf(search.getEmpId())%>' and the function to retrieve it which I have dhared in previous comment made very simple.

Regards
mohammad azaruddin
RE: Radio button in search container for each entry retrieved from database
March 28, 2013 2:15 AM
Answer

mohammad azaruddin

Rank: Expert

Posts: 439

Join Date: September 17, 2012

Recent Posts

Yeah..It may be helpfull to some one.