• Post Reply Bookmark Topic Watch Topic
  • New Topic

Listbox item selection problem with duplicate labels  RSS feed

 
Prasad Saya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a listbox where data is displayed. The problem is when two items in the list have the same label, I am not able to get the correct item details; the item details are different.

I am using MyFaces 2.0 on Tomcat 6.

I am looking for any ideas to solve this. Thanks.










 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "immediate=true" attribute is not some sort of AJAX directive. It's a directive indicating that NO DATA is to be sent to the server when the form is submitted. Not what you want, I don't think.

In HTML, a SELECT list consists of a label and a value. When you make a selection, the value associated with that label is what gets sent back to the server (assuming you didn't have "immediate" in your JSF!)

If 2 labels are identical, it doesn't matter, since the selection list is an ordered collection and the value chosen is based on WHICH label you selected, not on its text value.
 
Prasad Saya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, for the reply.

You are correct that immediate="true" is not required in this case (but, that was not the problem).

The problem was in the converter. The converter could not associate the selected name with its description. I removed the converter, and made some changes:

- Added a new attribute, item index, to the Item class
- List value is changed from Item object to Item's index: value="#{bean.itemIx}"
- The f:selectItems definition has item name as label and item index as value:
var="itm" itemValue="#{itm.ix}" itemLabel="#{itm.name}"
- And, related changes in the ItemsBean.

This works, fine.








 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!