Topic: nested标签的用法及疑问

  Print this page

1.nested标签的用法及疑问 Copy to clipboard
Posted by: realwangx
Posted on: 2005-03-29 11:34

nested,顾名思义,嵌套;
用法举例:
formBean定义:
public class PersonForm extends ActionForm {
Person person = new Person();

public void reset (ActionMapping mapping, HttpServletRequest request) {
  Address[] address = new Address[2];
  address[0]= new Address();
  address[1]= new Address();
person = new Person();
person.setAddress(address);
}

public Person getPerson() {
return this.person;
}

public void setPerson(Person person) {
this.person = person;
}
}

Person类:
public class Person {
private String lastName;
private String firstName;
private String age;
private Address address;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setAge(String age) {
this.age = age;
}
public String getAge() {
return age;
}
public void setAddress(Address address){
this.address = address;
}
public Address getAddress(){
return address;
}

}
Address类:
public class Address {
private String street1;
private String street2;
public String getStreet1() {
return street1;
}
public void setStreet1(String street1) {
this.street1 = street1;
}
public void setStreet2(String street2) {
this.street2 = street2;
}
public String getStreet2() {
return street2;
}
}
在jsp中使用标签
<html:form action="/showPerson">
<nested:nest property="person">
Last Name: <nested:text property="lastName"/><BR>
First Name: <nested:text property="firstName"/><BR>
Age: <nested:text property="age"/><BR>
P>
<nested:iterate id="child" name="person" property="address" type="nestedtaglibs.Address">
Current nesting is: <nested:writeNesting/><BR>
Street 1: <nested:text name="child" property="street1"/><BR>
Street 2: <nested:text name="child" property="street2"/><BR>
</nested:iterate >
</nested:nest>
<html:submit/>
</html:form>
这样能够很好的解决,对于form的复杂定义,也能够使关系变得清晰明了。
但是有一个问题:
当Person和Address是一对多的关系时,不管我怎么尝试,都没有成功。(更改了好多次源码)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923