...
For an example, see the following two classes:
Code Block |
---|
borderStyle | solid |
---|
title | MyAction.java | borderStyle | solid |
---|
|
/**
* @return a Collection of Foo objects
*/
public Collection getFooCollection()
{
return foo;
}
|
Code Block |
---|
borderStyle | solid |
---|
title | Foo.java | borderStyle | solid |
---|
|
/**
* @return a unique identifier
*/
public Long getId()
{
return id;
}
|
...
Here is the model bean used within the list. The KeyProperty for this bean is the id
attribute.
Code Block |
---|
borderStyle | solid |
---|
title | MyBean.java | borderStyle | solid |
---|
|
public class MyBean implements Serializable {
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return "MyBean{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
|
The Action has a beanList
attribute initialized with an empty ArrayList.
Code Block |
---|
borderStyle | solid |
---|
title | MyBeanAction.java | borderStyle | solid |
---|
|
public class MyBeanAction implements Action {
private List beanList = new ArrayList();
private Map beanMap = new HashMap();
public List getBeanList() {
return beanList;
}
public void setBeanList(List beanList) {
this.beanList = beanList;
}
public Map getBeanMap() {
return beanMap;
}
public void setBeanMap(Map beanMap) {
this.beanMap = beanMap;
}
public String execute() throws Exception {
return SUCCESS;
}
}
|
These conversion.properties
tell the TypeConverter to use MyBean instances as elements of the List.
Code Block |
---|
borderStyle | solid |
---|
title | MyBeanAction-conversion.properties | borderStyle | solid |
---|
|
KeyProperty_beanList=id
Element_beanList=MyBean
CreateIfNull_beanList=true
|
...
- The List does not have null values added for unavailable id values. This approach avoids the risk of OutOfMemoryErrors!
Code Block |
---|
borderStyle | solid |
---|
title | MyBeanAction.jsp | borderStyle | solid |
---|
|
<s:iterator value="beanList" id="bean">
<stextfield name="beanList(%{bean.id}).name" />
</s:iterator>
|
...