(JSF 1.2) From one SelectManyListBox to the other SelectManyListbox
Joined: Apr 10, 2012
I have the following problem:
I have to SelectManyListBoxes. In one of these the website displays numbers (1-10). When I click on one or more numbers and click on the commandbutton, the selected numbers schould be move to the second SelectManyListBox.
Do I need an ActionListener or an ValueChangeListener and how can I do that? The following code doesn't work.
It is better to use an action method than an actionListener. Action methods are simple POJO methods, easy to code, maintain, and test. Listeners are JSF-specific, more complicated to code and test, and more likely to be impacted if JSF makes architectural changes in the future.
I'm not sure why so many people are hung up on using Listeners. I think it's because there's old, stale documentation out on the Internet. Either that, or they can't be satisfied with a simple solution when a complicated one can be used instead. There are times when Listeners are required, but not as often as a lot of people seem to think.
As far as your particular problem goes, these conditions must be satisfied for the action to work properly.
1. All of the affected controls must be inside a JSF form.
2. When the command button is clicked, ALL controls in that form MUST have valid values. JSF is all-or-nothing, and if even a single input is invalid, ALL inputs are rejected and the action will not be fired. This ensures data integrity automatically.
3. To set the selected value of a secondary selection control from a primary control, the action method must set the secondary control's "value" property to the desired value. This value MUST be one of the values in the secondary control's selectItem collection. If it is not, it is rejected and a default value from that collection will be set. And you may also get a validation error.
Customer surveys are for companies who didn't pay proper attention to begin with.