Home
getCustomerSelectList method
This method retrieves customer objects and populates a list with these objects. For our purpose we only need the ssn:
![]()
Open the CustomerManager at the getCustomerSelectList method.
![]()
Change the code so that the label and the value of the drop-down menu are the same, namely the ssn: public List<SelectItem> getCustomerSelectList() {
List<Customer> customerList = getCustomerOrdered();
List<SelectItem> selectList = new ArrayList<SelectItem>();
// MessageFormat mf = new MessageFormat("{0}");
for (Customer customer : customerList) {
// selectList.add(new SelectItem(customer, mf.format(
// new Object[] { customer.getSsn() }, new StringBuffer(),
// null).toString()));
selectList.add(new SelectItem(customer.getSsn(),
customer.getSsn()));
}
return selectList;
}
Redeploy the application, and the drop-down list is populated with the SSNs of all the customers.
![]()
Note: Displaying SSNs in the user interface is not appropriate for a real application, but it illustrates the concept of populating a drop-down list with the results of a JPA query.
ibm.com/redbooks