users@glassfish.java.net

Visual Web JSF, nested drop down list

From: <glassfish_at_javadesktop.org>
Date: Sat, 02 May 2009 23:09:23 PDT

Hi,

Going on with my web app, I am having problems with two DDL and a Table components.

My idea is to load the first DDL with a database table. The second DDL is loaded with a related database table and working as follows: when I select an item from the first combo
the second must be loaded with the related rows of the related database table.

This works fine in my web app. The problem is when I load the Table component depending on the selected item of the second DDL. It does not work.

When you work with this, you must use Virtual Forms, RowSets and DataProviders that NetBeans IDE provides. Giving it as done, this is my code,

public void categoriasDD_processValueChange(ValueChangeEvent event) {
        Object selectedCategoriaId = categoriasDD.getSelected();
        try {
            categoriaDataProviderProducto.setCursorRow(
                    categoriaDataProviderProducto.findFirst("CATEGORIA.ID_CATEGORIA",
                    selectedCategoriaId));
            getSessionBean1().getSubcategoriaRowSetProducto().setObject(1, selectedCategoriaId);
            subcategoriaDataProviderProducto.refresh();
            form1.discardSubmittedValues("savesubcategorias");
        } catch (Exception e) {
            error("Cannot switch to categoria " + selectedCategoriaId);
            log("Cannot switch to categoria " + selectedCategoriaId, e);
        }
    }

to load the second DDL depending on the selected item. And

    public void subcategoriasDD_processValueChange(ValueChangeEvent event) {
        Object selectedSubcategoriaId = subcategoriasDD.getSelected();
        try {
            subcategoriaDataProviderProducto.setCursorRow(
                    subcategoriaDataProviderProducto.findFirst("SUBCATEGORIA.ID_SUBCATEGORIA",
                    selectedSubcategoriaId));
            getSessionBean1().getProductoRowSet().setObject(1, selectedSubcategoriaId);
            productoDataProvider.refresh();
            form1.discardSubmittedValues("saveproductos");
        } catch (Exception e) {
            error("Cannot switch to subcategoria " + selectedSubcategoriaId);
            log("Cannot switch to subcategoria " + selectedSubcategoriaId, e);
        }
    }

to handle the second DDL and load the Table component

And there is a method that is executed every time you make a select from anyone DDL.
This is the code,

public void prerender() {
        if (categoriasDD.getSelected() == null) {
            Object firstCategoriaId = null;
            try {
                categoriaDataProviderProducto.cursorFirst();
                firstCategoriaId = categoriaDataProviderProducto.getValue("CATEGORIA.ID_CATEGORIA");
                categoriasDD.setSelected(firstCategoriaId);
                getSessionBean1().getSubcategoriaRowSetProducto().setObject(
                        1, firstCategoriaId);
                subcategoriaDataProviderProducto.refresh();
            } catch (Exception e) {
                error("Cannot switch to categoria " +
                        firstCategoriaId);
                log("Cannot switch to categoria " +
                        firstCategoriaId, e);
            }
        }

        if (subcategoriasDD.getSelected() == null) {
            Object firstSubcategoriaId = null;
            try {
                subcategoriaDataProviderProducto.cursorFirst();
                RowKey rk = subcategoriaDataProviderProducto.getCursorRow();
                firstSubcategoriaId = subcategoriaDataProviderProducto.getValue("SUBCATEGORIA.ID_SUBCATEGORIA", rk);
                subcategoriasDD.setValue(firstSubcategoriaId);
                getSessionBean1().getProductoRowSet().setObject(
                        1, firstSubcategoriaId);
                productoDataProvider.refresh();
            } catch (Exception e) {
                error("Cannot switch to subcategoria " +
                        firstSubcategoriaId);
                log("Cannot switch to subcategoria " +
                        firstSubcategoriaId, e);
            }
        }
    }

And I guess this method is my wrong code.

Any idea?

Thanking in advance,
Jose Alvarez de Lara
[Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]

http://forums.java.net/jive/thread.jspa?messageID=344758