I want to display values in the drop-down list which comes from the database. The code is as follows in the <form>
:
<aui:select id="empName" name="empName">
<%
Employee employee;
Employee newEmployee = new EmployeeImpl();
int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();
for(int i=0; i<totalEmployees;i++) {
%>
<aui:option name = "opt" value ='<%=String.valueOf(newEmployee.getEmpFname())%>' />
System.out.println("newEmployee.getFname string value in loop: " +newEmployee.getEmpFname());
<%
}
%>
</aui:select>
It shows an a big empty list.
What should I do to get the values in the drop down list from the database?
I can make out the following from the code you have given:
Employee newEmployee = new EmployeeImpl();
int totalEmployees = EmployeeLocalServiceUtil.getEmployeesCount();
This code is before the for
loop, so what you are doing is you are just getting total-count
instead of the actual list of Employees
.
And here inside the for-loop:
<aui:option name = "opt" value ='<%=String.valueOf(newEmployee.getEmpFname())%>' />
you are just fetching an empty string ""
or null
value through the code newEmployee.getEmpFname()
since your newEmployee
object is not from the database but is created in the JSP itself and hence a big empty list :-)
I think you need to return a List<Employee>
also with the totalEmployees
(total-count) from the database rather than creating a new instance and then just calling .getEmpFname()
on that instance.