employee
とをプロパティとして持つテーブルがdepartment
ありaddress
ます。JSR 300でクラスの属性を検証したいのですがaddress
、住所と部門クラスの属性で検証に問題があります。これまでのところ、クラスの属性のみEmployee
が検証されています。私は何かが足りないのですか?
public class Employee {
private Integer id;
@NotEmpty(message = "First Name must not be blank.")
@Size(min = 1, max = 50)
private String firstName;
@NotEmpty(message = "Last Name must not be blank.")
@Size(min = 1, max = 50)
private String lastName;
@Digits(message = "Salary field must not be blank.", integer=32767, fraction = 2)
@NumberFormat(style = Style.NUMBER)
@NotNull(message = "Salary field must not be blank.")
private Double salary;
@Digits(message = "Select department", integer=100, fraction = 0)
@NumberFormat(style = Style.NUMBER)
@NotNull(message = "Select department")
private Integer dept_id;
@NotEmpty(message = "Select gender")
private String gender;
private boolean employeeStatus;
private Address address;
private Department department;
}
public class Address {
private Integer id;
@NotEmpty(message = "Country must not be blank.")
@Size(min = 1, max = 50)
private String country;
@NotEmpty(message = "City must not be blank.")
@Size(min = 1, max = 50)
private String city;
@NotEmpty(message = "Street must not be blank.")
@Size(min = 1, max = 50)
private String street;
private Integer emp_id;
}
public class Department {
private String name;
private Integer id;
}
jsp
<form:form commandName="employee" action="addEmployee.htm"
name="employeeForm">
<form:errors path="*" cssClass="errorblock" element="div" />
<fieldset>
<form:label path="firstName">First Name</form:label>
<form:input path="firstName" />
<form:errors path="firstName" cssClass="error" />
<br>
<form:label path="lastName">Last Name</form:label>
<form:input path="lastName" />
<form:errors path="lastName" cssClass="error" />
<br>
<form:label path="address.country">Country</form:label>
<form:input path="address.country" />
<form:errors path="address.country" cssClass="error" />
<br>
<form:label path="address.city">City</form:label>
<form:input path="address.city" />
<form:errors path="address.city" cssClass="error" />
<br>
<form:label path="address.street">Street</form:label>
<form:input path="address.street" />
<form:errors path="address.street" cssClass="error" />
<br>
<form:label path="salary">Salary</form:label>
<form:input path="salary" />
<form:errors path="salary" cssClass="error" />
<br>
<form:label path="gender">Gender</form:label>
<form:radiobutton path="gender" value="Male" />
Male
<form:radiobutton path="gender" value="Female" />
Female
<form:errors path="gender" cssClass="error" />
<form:label path="dept_id">Department</form:label>
<form:select path="dept_id">
<form:option value="" label="Please Select"></form:option>
<form:options items="${departmentList}" itemValue="id"
itemLabel="name" />
</form:select>
<form:errors path="dept_id" cssClass="error" />
<label></label><input type="submit" value="Add Employee"><br>
</fieldset>
</form:form>
さらに、給与フィールドでランダムな文字列を試してみると、例外が発生します。
Failed to convert property value of type java.lang.String to required type java.lang.Double for property salary; nested exception is java.lang.NumberFormatException:
この例外を取り除く方法は?