您可以使用 aMap
来填充f:selectItems
.
在您的托管 bean 中执行以下操作:
public class Bean
{
private Map<String, Employee> employees;
public Map<String, Employee> getEmployees()
{
if (employees == null)
{
initMap();
}
return employees;
}
private void initMap()
{
//get list of employees and put in map
employees = new HashMap<String, Employee>;
for (Employee e : someClass.getAllEmployees())
{
String name = e.getFirstName().subString(0,1);
name += ". ";
name += e.getLastName();
employees.put(name, e);
}
}
}
然后在您的 JSF 页面中,您可以使用:
<f:selectItems value="#{bean.employees}" />