File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes selectOneListbox value from an ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneListbox value from an ArrayList" Watch "selectOneListbox value from an ArrayList" New topic
Author

selectOneListbox value from an ArrayList

Nitin Sinha
Greenhorn

Joined: May 08, 2008
Posts: 17
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

Joined: Aug 18, 2008
Posts: 598

make use if <f:selectItems> tag not <f:selectItem>


My Blog SCJP 5 SCWCD 5
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

Sorry thats of not if.

make use of <f:selectItems> tag not <f:selectItem>
Nitin Sinha
Greenhorn

Joined: May 08, 2008
Posts: 17
after changing it to -


I am getting the following error -

Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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

Joined: Aug 18, 2008
Posts: 598

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: selectOneListbox value from an ArrayList