我有以下课程
public class Address {
private String unit;
private String street;
... getter and setters go here....
}
public class Person {
private String name;
private Address address;
public Person(){
address = new Address();
}
... getter and setters go here...
}
public class Employee extends Person {
...
}
例如,我可以使用以下代码访问地址类的单元字段
<s:form method="POST" action="updateEmployee">
<s:textfield name ="unit" label="Unit" value="%{employee.address.unit}" />
<s:textfield name ="name" label="Name" value="%{employee.name}" />
</s:form>
但是当我提交表单时,它会发送除地址类字段之外的所有字段。它显示单位为空。
@Action
public class myaction implements ModelDriven {
Employee emp = new Employee();
public String updateEmployee(){
System.out.println("Unit is" + employee.getAddress().getUnit();
System.out.println("Unit is" + employee.getName();
return "SUCCESS";
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
@Override
public Object getModel() {
return employee;
}