Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<h:selectOneMenu> problem

 
Joe Richard
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to use a javaBean to pull data and populate a someList<someObject>.
I want to use JSTL this is what I have that doesn't work.

<f:selectItems id="#{javaBean.someList.someObject.field1}" itemLabel="#{javaBean.someList.someObject.field2}" itemValue="#{javaBean.someList.someObject.field1}"/>

Any ideas how to do this with jsf?

 
B Nirvan
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSF one way to do is create a List of SelectItems and point the value attribute of the f:SelectItems to that list. Here is sample code

<f:selectItems value="#{stateBean.stateList}"/>

stateList is a backing bean property defined as

List<SelectItem> stateList;

You can also bind the value directly to your List instead of using List<SelectItems>, but it seems you don't get to define different values for itemLabel and itemValue. I am not very sure about this approach though

regards,
Nirvan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic