• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Listbox item selection problem with duplicate labels

 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.










 
Saloon Keeper
Posts: 28401
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.








 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic