2012-08-01 5 views
2

데이터베이스의 데이터로 채워지는 양식이 있습니다. 는 전에 나의 문제, 일부 조각을 설명하는 시작 :JSP 드롭 다운이 객체를 제출하지 않습니다.

한 클래스 :

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

@Column(name = "deleted") 
private boolean deleted; 

getter/setter 
} 

2 등석에는 EmployeeController의 방법은 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( 
        Sort.Direction.ASC, 
        "area" 
        ) 
       )); 
    return "employees/dialogUpdateEdit"; 
} 
에 데이터를 반환하기 위해 호출

// @Entity for employees 
public class Employee { 
@Id 
@GeneratedValue 
@Column(name = "ID") 
private long id; 

@ManyToOne 
@JoinColumn(name = "area") 
private Area area; 

@Column(name = "name") 
private String name; 

getter/setter 

영역에 대한 드롭 다운을 보여주는 jsp 및 n이 없으면 EW 직원, 알려진 데이터

<form:form action="employees/ajax" commandName="employeeModel" method="POST" id="createForm"> 
    <table class="fullWidth"> 
     <tr> 
      <td>Area</td> 
      <td> 
       <form:select path="area" items="${areas}" class="fullWidth"> 
       </form:select> 
      </td> 
     </tr> 
     <tr> 
      <td>Employee Name</td> 
      <td><form:input path="name" class="fullWidth"/></td> 
     </tr> 
     <tr> 
      <td colspan="2"> 
       <input type="submit" value="Save Changes" id="btnSaveEmployee" class="fullWidth" /> 
      </td> 
     </tr> 
    </table> 

    <!-- adding hidden field to hold id on update --> 
<form:hidden path="id" /> 

</form:form> 

컨트롤러 방법 검증을하고 약간의 오류 또는 문제를 들어하지

@RequestMapping(value = "/ajax", method = RequestMethod.POST) 
protected @ResponseBody ValidationResponse createOrUpdate(
     @Validated @ModelAttribute("employeeModel") Employee employee, 
     BindingResult bindingResult) { 

    if (!bindingResult.hasErrors()) { 
     employeeService.createOrUpdate(employee); 
    } 

    return validate(employee, null, bindingResult); 
} 

반환하거나 반환됩니다 이 모두 잘 작동을 드롭 다운은 데이터 가져 채워집니다 입력에 채워집니다. 내가 제출을 클릭하면 는하지만, 나는 다음과 같은 오류가 발생합니다 :

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

지금까지 내가 그것을 이해, 형태는 '지역'대신 목록에서 개체를 바인딩의 일반 문자열을 제출합니다.

문자열을 제출하지 않고 양식을 제출할 수있는 양식은 어떻게 얻을 수 있습니까? 제 바인딩에 문제가 있습니까?

도움 주셔서 감사합니다. 난 당신이 내 자신의 질문에 대답하기 위해 이러한 유형의 코드

<select name="area" id="area" >  
    <option value="${areas}">${areas}</option> 
</select> 
+0

당신이 당신의 컨트롤러 방법 매핑 URL "직원/아약스를"게시 할 수 :

이 링크는 내가 찾던 알고 있기 때문에 내가 찾은 그 주제에 최고의 짧은 튜토리얼이있다? – Jason

답변

1

을 시도하고 사람이 모르게 나에게 도움이 학점을 끄는 것을 희망 할 수 선택에 대한 생각

관련 문제