データを挿入/更新するフォームがあります。コマンド オブジェクト (Bean) クラスには、次のような形式で配置される Date フィールドがあります。
<form:hidden path="createdDate">
フォームを送信すると、BindResult.hasErrors() が true として検証されます。
日付オブジェクトをバインドする必要があると思いますが、コマンド オブジェクト フィールドに対してはどのように行われますか?
フォーム Bean のコードは次のとおりです。
@Entity
@Table(name = "Employee")
public class Employee {
@Id
@GeneratedValue
@Column(name="id")
private int id;
@Column(name="EmployeeName")
private String employeeName;
@Column(name="CreatedDate")
private Date createdDate;
//Setter and getter methods
}
エラー:
[Field error in object 'employee' on field 'CreatedDate': rejected value [Mon Sep 17 20:35:26 IST 2012]; codes [typeMismatch.employee.CreatedDate,typeMismatch.CreatedDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [subject.CreatedDate,CreatedDate]; arguments []; default message [CreatedDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'CreatedDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'CreatedDate': no matching editors or conversion strategy found]]