PDA

View Full Version : Binding to a dynamically created list


leetgeezer
May 22nd, 2007, 09:38 AM
I have a Command Bean (only part shown for simplicity)


class Album {
....
private List<String> songs;
....
}


I am using the AbstractWizardFormController. On the first page, the user
creates dynamically some number of input boxes (using JS) which get assigned
ids and names "song[0]", song[1]", etc... The boxes may also be deleted.

On the second page the user is displayed the list of songs and verifies it.

The problem happens if the user clicks the 'back' button of the browser on the second page. If now he deletes some of the songs, the previously bound songs are not cleared from the command object. In other words, when he entered

"Song1"
"Song2"

on the first page, clicked "submit", clicked "back" on the browser, deleted box with "Song2", clicked submit, the song2 would stay in the command and would be displayed on the verification page.

How to cope with this problem? I see two solutions:
1) Clear the song list in the command objects before standard binding on page 1. However I can't see which method of the controller shall I override
2) Use the trick with "_" prefix before id. Requires a bit mangling with JS.

Any thoughts?

pmularien
May 22nd, 2007, 12:47 PM
1) Clear the song list in the command objects before standard binding on page 1. However I can't see which method of the controller shall I override
This is what I have done in the past to avoid this problem. You should look at overriding the currentFormObject method (assuming you've set this up as a session form, which is typical for a wizard-type controller).

leetgeezer
May 31st, 2007, 12:59 PM
Thanks, that saved my day :}