This is how I do it:-
Code:
/*
* EditGlobalOptionsCommand.java
*
* Created on 04 December 2005, 12:21
*/
package org.xxxx.xxxxadmin.command;
import java.util.ArrayList;
import java.util.List;
import org.xxxx.xxxxadmin.bean.PostageBandBean;
/**
* A POJO that acts as a Spring command for editing the global options
*
* @author Matt Parker (matt@mpcontracting.co.uk)
*/
public class EditGlobalOptionsCommand
{
private String generalCaption;
private String generalTextTop;
private String generalTextBottom;
private String ringingCaption;
private String ringingTextTop;
private String ringingTextBottom;
private List postageBands;
<...SNIP...>
/**
* Sets the list of postage bands
*
* @param postageBands The list of postage bands
*/
public void setPostageBands(List postageBands)
{
this.postageBands = postageBands;
}
/**
* Retrieves the list of postage bands
*
* @return The list of postage bands
*/
public List getPostageBands()
{
if (postageBands == null)
{
postageBands = new ArrayList();
}
return (postageBands);
}
/**
* Adds a postage band bean to the list
*
* @param postageBandBean The postage band bean
*/
public void addPostageBand(PostageBandBean postageBandBean)
{
getPostageBands().add(postageBandBean);
}
}
I have a framework that I've written that allows me to intercept the creation of the form backing object and add the appropriate number of beans in the view controller and to adjust the number in the form controller if the submitted number is different (in other words I can call getFormBackingObject() from within my controllers and get my command object).
You can get a version of this from here (it's Apache licensed so do what you like with it) - http://www.zen29969.zen.co.uk/mpsc-modules-0.2.zip - I'm still waiting on Sourceforge to approve the project to get hosting there.
In particular, look at uk.co.mpcontracting.modules.spring.controller.Abst ractFormController and uk.co.mpcontracting.modules.spring.controller.Abst ractViewController to get some ideas.
There is JavaDoc, but no other documentation. Of course, I don't accept any responsibility for bugs you may find etc etc
Bob