Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

For an example, see the following two classes:

Code Block
borderStylesolid
titleMyAction.java
borderStylesolid
/**
 * @return a Collection of Foo objects
 */
public Collection getFooCollection()
{
    return foo;
}
solid
Code Block
borderStyle
titleFoo.java
borderStylesolid
/**
 * @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.

solid
Code Block
borderStyle
titleMyBean.java
borderStylesolid
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.

solid
Code Block
borderStyle
titleMyBeanAction.java
borderStylesolid
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.

solid
Code Block
borderStyle
titleMyBeanAction-conversion.properties
borderStylesolid
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!
solid
Code Block
borderStyle
titleMyBeanAction.jsp
borderStylesolid
<s:iterator value="beanList" id="bean">
  <stextfield name="beanList(%{bean.id}).name" />
</s:iterator>

...