so the problem is pretty straightforward. i need listselect component to accept multiple items of same value. i know i could use other components, but i listselect really does well with my demands, except for not acceptings items with same value part.
Hmm I haven’t really used ListSelect much, I always use the basic Select. Anyhow, what does it really mean that you have many items in it with the same value? I have a hard time figuring out a use case for that. Should the items be the same as of the value you get out when you in your software take listSelect.getValue() or should the identifying string in the component have the same name?
If you really want it, I guess you could have a better container behind.
Foo is the class that you list in the select. The container now uses own genarated id for the objects = no possible collisions. The caption shown as item choises are stored sepearately in a property, so is the item too.
So if I understand you correctly you want getValue() on your list select to return the same value for different strings (but with the same value) selected in the UI?
I would suggest that you add a new container property that contains the actual value and use something else for the item IDs. A short example:
Populate the select something like this
ListSelect myListSelect = new ListSelect();
myListSelect.addContainerProperty("ACTUAL_VALUE", Object.class, null);
for (Object value : myValues) {
Item item = myListSelect.addItem(captionFor(value));
item.getItemProperty("ACTUAL_VALUE").setValue(value);
}
Note that we are using the caption for the value as the item ID, which by default will be shown in the UI.
And when grabbing the value (e.g. in your valuechange listener or wherever)
well basically, i wanted to add a string of lets say value “A” to a listselect component. ok.
now i try to add another string with the same value. result? only one “A” is in listselect. i guess the component checks if the same value (“A”) already exists and if it does, no more “A”-s are allowed.
i went back to ordinary, multi-row styled textfield. accepting more of the same values was more important in this particular situation then other advantages listselect offers over textfield.
after a while it hit me. maybe i could create and item and give him different id’s and same values. Just the same as you suggested, jonatan.