Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

selectOneMenu

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get to the selected items ID value, as apposed to the actual value, because I use this reference to look up something in the DB, and its not clear from the API how to get to this.

Binding to the value is no problem, but this is not neccessary unique in the database.

Do I need to bind the component to a UI object to get to this, or is there a much simplier way I am overlooking?

Thanks.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is this something related to JSF?

Not understood your question exactly
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


On submit, the value of the selected item is binded to roleId. However, I want the id Value, not the displayed value of the item...so in HTML it would be:



roleId = UUID123456 (I want this)

as apposed to

roleId=Displayed Value (I dont want this)

regards
[ December 18, 2006: Message edited by: James Clinton ]
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try folloing code

In Jsp
<f:selectItems value="#{myBean.listitem}"/>


In bean create getter method

getListitem() whose return Type shold be SelectItem[]

in method you can create SelectItem[] whose syntax is as follows

SelectItem[] listitem = new SelectItem[size];

listitem[i] = new SelectItem(storedColumnValue,displayColumnValue);


Hope this will help you
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,


<h:selectOneMenu id="roles" value="#{userMaintainCommand.roleId}" required="true">
<f:selectItems value=".."/>
<f:selectItems value=".."/>
</h:selectOneMenu>



This code will bind the userMaintainCommand.roleId to the value not to the item that is displayed in the select list.

You should return Arraylist<SelectItem> for using with <f:selectItems>.
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know which is the selected option when binding to the ArrayList?

Cheers.
[ December 19, 2006: Message edited by: James Clinton ]
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The selected item is the one in the valuebinding of the h:selectOneMenu. You can use this for pre-selection.
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You should return Arraylist<SelectItem> for using with <f:selectItems>.



Apoligies if this is a stupid question, but what exactly do you mean, how can this achieved?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSF

MyBean
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

So back to my orginal problem of getting hold of the selected value, not label, how can this be achieved

Previously doing this binds the selected items label to selectItem which is a String in the backing bean.

---JSF
<h:selectOneMenu id="roles" value="#{myBean.selectItem}">
<f:selectItems value="#{myBean.selectItems}"/>
</h:selectOneMenu>

---MyBean.java
String selectItem;

regards
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally discovered how to do this....

You need to bind the selectItems to a object of type http://www.docjar.com/docs/api/javax/faces/component/UISelectOne.html

binding="#{bean.uiSelectOneObj}"



Then, you can call getValue() on it.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The getValue() returns exact the same as you definies in the valuebinding "{myBean.selectItem}". So I don't get the problem.
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the 'value="#{bean.stringValue"' binding, binds local value, not the key value....or this is what i have discovered.

So

SelectItem.setLabel("displayed value");
SelectItem.setValue("key");

in HTML

<OPTION value="key-value">displayed-value</OPTION>

I have found the value binding always returns the local value, not the key value.

Please correct me if i have missed something..regards. J.
[ December 28, 2006: Message edited by: James Clinton ]
 
He's giving us the slip! Quick! Grab this tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic