如何在bean验证框架中访问validation.xml中的对象

时间:2010-12-20 00:54:55

标签: spring-modules

我的课程:

public class Employee {

private String firstName;
private String lastName;
private Department department; 
//with getters and setters
}

我的employee-validation.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<validation xmlns="http://www.springmodules.org/validation/bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://localhost:8080/BVF http://localhost:8080/BVF/validation.xsd">

<class name="Employee">
<validator class="EmployeeValidator"/>

<property name="firstName">
<not-blank message="FirstName cannot be left blank"/>
<length min="5" max="20" message="First Name Length cannot be less than 5 or more than 20"/>
</property>

<property name="lastName">
<not-blank message="LastName cannot be left balnk"/>
<length min="5" max="20" message="Last Name Length cannot be less than 5 or more than 20"/>
</property>

<property name="department.name">
<not-blank message="Name cannot be blank"/>
<length min="5" max="20" message="Name Length cannot be less than 5 or more than 20"/>
</property>

<property name="department.pinCode">
<not-blank message="Pin Code cannot be left blank"/> 
<regexp expression="^[A-Z\d{1}]\d{4}[\s\-]*\d*$" message="PinCode is invalid"/> 
<length min="5" max="10" message="Pincode length should be between 5 and 10"/>

</property>

</class>

</validation>

有人可以告诉我如何访问部门对象的元素,即这部分

<property name="department.pinCode">

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,即使用级联属性。