Ok, let's say you have a bean "Company" and a "CompanyDao" to get all companies. Let's say you have an "Employee" associated with exactly one "Company", and this association is made through the company property of the "Employee" bean.
Code:
class Company {
name
}
class Employee {
name
company
}
interface CompanyDao {
getCompanies();
}
(i use groovy syntax for example shorthand;-)) ...
The first thing you need is a ValueModel providing access to the list of companies, to be used to populate the comb-box's list of selectable items. You can do this as follows:
Code:
Function companyAccessor = new Function() {
public Object evaluate() {
return companyDao.getCompanies();
}
};
ValueModel companyListHolder = new RefreshableValueHolder(companyAccessor);
Then, you need a value model providing access to the selected item - in this case the "company" property of the employee bean.
If you're editing this employee's properties on a form, just wrap the Employee in a form model and use the create* factory methods to create the appropriate combo-box control, with the appropriate property as the "selection property":
Code:
SwingFormModel employeeModel = SwingFormModel.createFormModel(new Employee());
JComboBox employeeCompanySelector = employeeModel.createBoundComboBox("company", companyListHolder, "name");
In the above createBoundComboBox call "company" is the property on the employee bean to represent the selecte item, companyListHolder provides the list of selectable items, and "name" is the Company property to render to display an item in the selectable list.
Hope this helps! Of course there are further abstractions - like the DialogPage classes - that create form models for beans as part of create/edit transactions for you. This example just shows the base APIs in play.