Announcement Announcement Module
No announcement yet.
JSP dropdown does not map to object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSP dropdown does not map to object

    I have a form that gets populated with data from the database. Before is start describing my problem, some snippets:

    One class:

    // @Entity for areas
    public class Area {
    @Column(name = "area")
    private String area;
    @Column(name = "deleted")
    private boolean deleted;
    Second class

    // @Entity for employees
    public class Employee {
    @Column(name = "ID")
    private long id;
    @JoinColumn(name = "area")
    private Area area;
    @Column(name = "name")
    private String name;
    The method in EmployeeController called to return data to the jsp

    protected String createDialog( @PathVariable("id") Long id, Model model ){
        Employee employee = id == 0 ? new Employee() : employeeService.findById(id);
        //return employee
        model.addAttribute("employeeModel", employee );
     //add data needed to create dropdown holding areas
        //areaService.findAll returns a List<Area>
        model.addAttribute("areas", areaService.findAll( 
                    new Sort( 
        return "employees/dialogUpdateEdit";
    The jsp, showing the dropdown for the areas and, if no new employee is returned, the known data

    <form:form action="employees/ajax" commandName="employeeModel" method="POST" id="createForm">
        <table class="fullWidth">
                    <form:select path="area" items="${areas}" class="fullWidth">
                <td>Employee Name</td>
                <td><form:input path="name" class="fullWidth"/></td>
                <td colspan="2">
                    <input type="submit" value="Save Changes" id="btnSaveEmployee" class="fullWidth" />
        <!-- adding hidden field to hold id on update -->
    <form:hidden path="id" />   
    The controller method doing validation and either returning some errors or not
    @RequestMapping(value = "/ajax", method = RequestMethod.POST)
    protected @ResponseBody ValidationResponse createOrUpdate(
            @Validated @ModelAttribute("employeeModel") Employee employee,
            BindingResult bindingResult) {
        if (!bindingResult.hasErrors()) {
        return validate(employee, null, bindingResult);
    For the problem: This all works fine, dropdown is populated, data gets filled into the inputs. But when I click the submit, I get the following error:
        java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.whatever.Area] for property 'area': no matching editors or conversion strategy found
    As far as I understand it, the form just submits the plain string for 'area' instead of binding the objects from the List.

    How do I get the string submitted for 'area' to be the appropriate object of type Area? Otherwise validation will always fail.

    Thanks for your help!
    Last edited by ximarin; Aug 1st, 2012, 05:49 AM. Reason: spelling