OK, thank you. This is my solution:
I made a custom FormBackingObject as an inner class "userChoice" of my controller. A userChoice has a list of selected Newsletters (just simple Strings).
Code:
class UserChoice {
private List<String> selection = new ArrayList<String>();
public List<String> getSelection(){
return selection;
}
}
This method creates the formBackingObject:
Code:
protected Object formBackingObject(HttpServletRequest request) throws Exception {
LOGGER.info("[FBO]");
UserChoice userChoice = new UserChoice();
userChoice.getSelection().add("Movie");
userChoice.getSelection().add("Garden");
return userChoice;
}
This is the referenceData-Method that collects *all possible* newsletters:
Code:
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
LOGGER.info("[REFERENCE DATA]");
Map<String,Object> model = new HashMap<String,Object>();
List<String> newsletters = new ArrayList<String>();
newsletters.add("Pets");
newsletters.add("Movie");
newsletters.add("Garden");
newsletters.add("Art");
model.put("newsletters", newsletters);
return model;
}
My checkboxes are bound to the userChoice's selection:
Code:
<spring-form:form>
<spring-form:checkboxes path="selection" items="${newsletters}" />
<input type="submit" name="submit" value="Submit" />
</spring-form:form>
The boxes corresponding to the user's selection are preselected. That's good. Unfortunately I don't get the user's changes:
Code:
protected void doSubmitAction(Object command) throws Exception {
LOGGER.info("[DO SUBMIT ACTION]");
UserChoice userChoice = (UserChoice)command;
userChoice.logSelection();
}
logSelection still shows Movie and Garden, even when I select only Pets and Art. Any idea why? BTW: Where do I compose the model for the success view? Do I have to use onSubmit instead of doSubmitAction?