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

selectOneListbox value from an ArrayList

 
Nitin Sinha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a method that returns arrayList which stores a List of Country names from Database using Session Bean. Please see the code below -



Now, I have given the definition for this java class file in faces-config.xml and now how best can I call this list in my JSF - JSP Page ?

I know we can call this Array List in DataTable but then I can't embedd DataTable tags in selectOneListbox because that would give each country in seperate combo boxes. So, if there are 110 countries , it lists each country in 110 seperate combo boxes.

So, I devised this way of calling -


But this also doesnt seem to be viable solution because there is now way of calling index values in value tag and I can't keep on writting seperate selectItem for all Countries.

Please tell me that how best can I call the Array List of Values in Select One List Box ?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make use if <f:selectItems> tag not <f:selectItem>
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry thats of not if.

make use of <f:selectItems> tag not <f:selectItem>
 
Nitin Sinha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after changing it to -


I am getting the following error -

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make an array List of selectItems in backing Bean and then give its reference in the jsp page. Also don't give as value binding in h:select and f:select.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have an array also in backing bean like


and in jsp page give value as #{bean.location}

Hope this may sole your problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic