Results 1 to 4 of 4

Thread: Example for addSelector

  1. #1
    Join Date
    Aug 2004
    Location
    Whitehorse, YT, Canada
    Posts
    26

    Default Example for addSelector

    Hi!

    Would you please provide an example of using addSelector from the BeanFormBuilder interface? I have a class, Community, which is populated from a database and I have a DAO which will load a List of Community objects, but how do I pass that to the addSelector?

    Thanks!

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    smv,

    Currently addSelector only applies to properties that are Enums; more specifically, instances of org.springframework.enums.CodedEnum, which is currently in the Spring sandbox. The list of available selectable items will be populated from the list of enums associated with the enum type of the property at the "formPropertyPath."

    In general, I would like to add that the FormBuilder interfaces as is are still very experimental. They're still part of the framework that has yet to be "run through the ringer" and flushed out to a stable state.

    Now, if you need a combo box populated from the items returned by a DAO method, and you need to bind the selected item to a bean property, there are other, straightforward ways to do it using the FormModel API and the "RefreshableValueHolder" to pull a collection of objects from a DAO method. See the: createBoundComboBox methods of the SwingFormModel class on org.springframework.richclient.forms. I will also post an example here in a bit (gotta do some work now though ;-))

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    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.

  4. #4
    Join Date
    Nov 2004
    Location
    IL, USA
    Posts
    61

    Default

    But how to handle the situation if you want to assign id of the value, I mean I have possible values like:

    id:2, value="the tree is white"
    id:6, value="the tree is yellow"
    id:7, value="the tree is green"

    I want the id which relates to the text value to be assigned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •