« Return to Thread: How to Bind an Entity Bean to a DropDownList

How to Bind an Entity Bean to a DropDownList

by FromDotNetToJava :: Rate this Message:

Reply to Author | View in Thread

Environment: NB 6.1, Vista OS, MySql 5.1, GlassFish.

Over the past day I have sought clear direction as to how to bind a JPA entity bean to a dropdownlist. I examined the following Nabble links for assistance:

http://www.nabble.com/Visual-Web-Designer%3A-Bind-an-EJB3-entity-bean-to-a-dropdown-list-td14888317.html#a14920128
http://www.nabble.com/Dropdown-list-of-user-tp11783679p11801513.html

Here is what I have done thus far:

<entity bean>
I used the IDE to auto-gen the POJO entity which is a simple lookup table in the Db:
     id            unsigned int,
     domain     varchar(50)
     value       varchar(255)
</entity bean>

<in an entity manager>
public List getCountryLookups() {
        Query query = _EM.createNamedQuery("Lookup.findByDomain");
        query.setParameter("domain", "Country");
        return query.getResultList();
    }
</in an entity manager>

<entended an ObjectListDataProvider>
public class CountriesDataProvider extends ObjectListDataProvider {

    private static ArrayList _ArrayList;
   
    public CountriesDataProvider() {
        if (_ArrayList == null) {
            FacesContext fc = FacesContext.getCurrentInstance();
            _ArrayList = new ArrayList();
            _ArrayList.add((List<Lookup>) fc.getExternalContext().getApplicationMap().get("countries"));
            setList(_ArrayList);
        }
    }
}
</entended an ObjectListDataProvider>

<getter and setter in page fragment>
private CountriesDataProvider _Countries = new CountriesDataProvider();

    public CountriesDataProvider getCountries() {
        return _Countries;
    }
</getter and setter in page fragment>

Now this is where things get hazy... I have binded the dropdownlist to the getcountries property - but the rendering didn't work.

So my questions are:

1. Bind to the selectItems node?
2. Is there a better method for binding an entity bean to the ddl?
Thanks,

Chris

 « Return to Thread: How to Bind an Entity Bean to a DropDownList