views:

74

answers:

1

We have a requirement to select only one element from rich:pickList. How do you disable the controls or prevent folks from moving additional data from the left hand side after an item is selected.

A: 

I don't really understand this requirement as the rich:pickList is dedicated to make a list selection from another list.

Ideally, a component like <h:selectOneListbox> will be more easier to use in your case.

However, if you really must use the rich:pickList, I would suggest you to use the onlistchange Javascript event. This event is called when the list will be changed. So what you can try is to get the size of the selected list, and if this size is equals to one (i.e. the use already selected one item), you simply return false. This will normally cancel the action done by the user (i.e. the addition of another element).

Another idea, still based on the usage of onlistchange event (or maybe onlistchanged is better in this case) is to disable the buttons when one element is added in the chosen elements list.

Last idea is to do the same thing as in my second idea, but using Ajax. As you can see in the Richfaces Live Demo site, there is an example of usage of this component with a panel that counts the number of selected elements. So you can try to disable the addition buttons when this counter is equals to 1.

romaintaz