2

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)

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

But I need to get values in map from database using hibernate. i dont know that, that is why i used list. i need only ID and Fname in map. But class contain other fields also. here i am stuckup, how to reterive id and fname in map from Database using hibernate
Iterate over list recieved from DAO layer and prepare a map and send it to populate a dropdown on JSP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.