Actually, a List has one advantage over a Map in that one has control
over the order in which the elements are displayed.

BTW, the List (or, more generally, the Collection) is assumed to contain
SelectItem instances.

- Brendan

-----Original Message-----
From: Rick Reumann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 08, 2005 12:21 PM
To: MyFaces Discussion
Subject: Best way to use object properties from a List to create Select
Items?


What's the best way in JSF/MyFaces to use a List to create a select
options list? I know the SelectItems can be built from a Map, but it
doesn't seem to support a list of objects too well.  Can I at least
set them easily looping over my collection manually?

For example in JSTL.. I can creat my options ...

<c:forEach items='${employees}' var='emp'>
    <html:option value="${emp.empID}">${emp.name}</html:option>
</c:forEach> 

Can I do this with a dataList inbetween  <h:selectOneMenu > tags?

It would be cool if the selectItems tag supported:

<f:selectItems collection="#{employees}" label="${name} value="${empID}"
/>

(above would loop over your collection of employees pull out Employee
and call appropriate getters - getName getEmpID )

-- 
Rick

Reply via email to