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

Re: How to Bind an Entity Bean to a DropDownList

by FromDotNetToJava :: Rate this Message:

Reply to Author | View in Thread

After poking around (NB team there is very poor documentation for this) I crafted a solution...

First off, let me say that I am not using the non-stylable WoodCrap DrowDownList component. Rather, I am implementing a Standard DropDownList.

I pulled my lookup table values in ServletListener.contextInitialized() and stored those values as an arraylist of SelectItems in the ServletContext to save on Session bloat:

<code>
        ServletContext sc = event.getServletContext();

        // Global Db data cache in VM
        Coordinate coordinate = new Coordinate();
        coordinate.Initialize();
       
        // Countries
        List list = (List<Lookup>) coordinate.getCountryLookups(); // see entity manager above
        ArrayList CountryAL = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            Lookup lookup = (Lookup) list.get(i);
            CountryAL.add(new SelectItem(lookup.getLookupid().toString(), lookup.getValue()));
        }
        sc.setAttribute("countries", CountryAL);
        sc.setAttribute("default country", "237");
</code>

Secondly, I created get properties in my page fragment:

<code>
public ArrayList getCountries() {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (ArrayList) fc.getExternalContext().getApplicationMap().get("countries");
    }
   
    public String getDefaultCountry() {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (String) fc.getExternalContext().getApplicationMap().get("default country");
    }
</code>

Lastly, I did the binding using the page fragment design object tree view...
1. select the DDL > right click > Property Bindings > select DefaultCountry as the binding target.
2. expand the DDL. You now see the f:selectItems name (mine is called ddlCountryItems).
3. select the Items name > right click > Property Bindings > select countries as the binding target.

If NB acts buggy save, close, reopen, clean and build.

Compile and life should be all good. I hope this really does help out someone.
Thanks,

Chris

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