user3639244
user3639244

Reputation: 61

Populate Dropdown list from Using Spring,Hibernate

Experts,

Class EmployeeEntity
    {
        id
        Fname
        Salary
        Phone
    }

Controller.java

@RequestMapping(value = "/list")
public String listEmployee(ModelAndView map)
{

    map.addObject("employee", employeeManager.getEmp());

    return "emp";


}

EmployeeDAO.java

@Override
public List<EmployeeEntity> getEmp() {
    return this.sessionFactory.getCurrentSession().createQuery("select e.id, e.firstname from EmployeeEntity e").list();
}

emp.jsp

<form:form method="POST">

 <form:select path="Fname">
    <form:options items="${employee}" />
</form:select>

</form:form>

This are my files. I am not geting values in drropdown.Please help me How to find out problem. I need to populate list with Fname ,and Id as value in list

Error

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
    org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)

Upvotes: 2

Views: 2781

Answers (1)

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29316

First thing you have to use map instead of list. You can have a refernce to below code:

@RequestMapping(value = "/list")
public Map listEmployee(ModelAndView map) throws Exception {
    Map referenceData = new HashMap();
    Map<String,String> country = new LinkedHashMap<String,String>();
    country.put("US", "United Stated");
    country.put("CHINA", "China");
    country.put("SG", "Singapore");
    country.put("MY", "Malaysia");
    referenceData.put("countryList", country);
}

And iterate over Map on JSP to construct dropdown as below:

<form:select path="country">
   <form:option value="NONE" label="--- Select ---"/>
   <form:options items="${countryList}" />
</form:select>

Upvotes: 1

Related Questions