webtier@glassfish.java.net

Visual Web JSF. Problem in the prerender() method.

From: <webtier_at_javadesktop.org>
Date: Sun, 28 Jun 2009 01:48:38 PDT

Hi,
 
Firstable I am going to introduce my code,
 
            if (productoDataProviderPieza.getRowCount() > 0) {
                try {
                    if (!getRequestBean1().getAction().equalsIgnoreCase("productosDD")) {
                        List<Option> productosDDDefaultOptions = (List<Option>) productosDD.getItems();
                        Iterator<Option> i = productosDDDefaultOptions.iterator();
                        Option o = null;
                        Object idPieza = null;
                        if (i.hasNext()) {
                            o = i.next();
                            firstProductoId = o.getValue();
                            String miLabel = o.getLabel();
                            getApplicationBean1().getGetPiezaRowSetPK().setObject(1, miLabel);
                            getPiezaDataProviderPK.refresh();
                            RowKey rk = getPiezaDataProviderPK.findFirst("PIEZA.ID_PRODUCTO", firstProductoId);
                            idPieza = getPiezaDataProviderPK.getValue("PIEZA.ID_PIEZA", rk);
                        }
                        if (idPieza == null) {
                            getApplicationBean1().getPiezaRowSet().setObject(1, new Integer(-1));
                            getApplicationBean1().getPiezaRowSet().setObject(2, new Integer(-1));
                            piezaDataProvider.refresh();
                            getRequestBean1().setMensaje("No hay Productos");
                        } else {
                            getApplicationBean1().getPiezaRowSet().setObject(1, idPieza);
                            getApplicationBean1().getPiezaRowSet().setObject(2, firstProductoId);
 
                            if (piezaDataProvider instanceof RefreshableDataProvider) {
                                piezaDataProvider.refresh();
                            
                                tableRowGroup1.setRowKey(piezaDataProvider.findFirst(
                                    new String[]{"PIEZA.ID_PIEZA", "PIEZA.ID_PRODUCTO"},
                                    new Object[]{idPieza, firstProductoId}));
                            }
                        }
                    }
                } catch (Exception e) {
                    error("Cannot switch to producto " +
                            firstProductoId);
                    log("Cannot switch to producto " +
                            firstProductoId, e);
                }
            } else {
                try {
                    getApplicationBean1().getPiezaRowSet().setObject(1, new Integer(-1));
                    getApplicationBean1().getPiezaRowSet().setObject(2, new Integer(-1));
                    piezaDataProvider.refresh();
                    getRequestBean1().setMensaje("No hay Productos");
                } catch (Exception e) {
                    error("Cannot switch to producto " +
                            firstProductoId);
                    log("Cannot switch to producto " +
                            firstProductoId, e);
                }
            }
        }
 
 
This is the code in the prerender() method.
 
I have made the web app works but not so fine as I would like. My problem the first time I select a Subcategoria from its
DDL beacause productosDD is a nested Producto DDL. I hope the piezaDataProvider refresh with the new calculated values
and my table show the new rows. But it does not work. And it does not only for the first time. The rest of the time the web app
works ok.
 
And I do not Know what I am making wrong. I think the problem is in the prerender() method. I mean,
 
                            if (piezaDataProvider instanceof RefreshableDataProvider) {
                                piezaDataProvider.refresh();
                            
                                tableRowGroup1.setRowKey(piezaDataProvider.findFirst(
                                    new String[]{"PIEZA.ID_PIEZA", "PIEZA.ID_PRODUCTO"},
                                    new Object[]{idPieza, firstProductoId}));
                            }

I do not think these are the correct sentences.
Any idea?
 
Here is the rest of the, needed to understand it, code,
 
piezaRowSet.setDataSourceName("java:comp/env/jdbc/ALMACEN_ApacheDerby");
        piezaRowSet.setCommand("SELECT ALL ALMACEN.PIEZA.ID_PIEZA, ALMACEN.PIEZA.ID_PRODUCTO, ALMACEN.PIEZA.NOMBRE, ALMACEN.PIEZA.DESCRIPCION, ALMACEN.PIEZA.DISPONIBILIDAD, ALMACEN.PIEZA.ENTREGA, ALMACEN.PIEZA.PRECIO, ALMACEN.PIEZA.IMAGEN FROM ALMACEN.PIEZA INNER JOIN ALMACEN.PRODUCTO ON ALMACEN.PIEZA.ID_PRODUCTO = ALMACEN.PRODUCTO.ID_PRODUCTO WHERE ALMACEN.PIEZA.ID_PIEZA = ? AND ALMACEN.PIEZA.ID_PRODUCTO = ?");
        piezaRowSet.setTableName("PIEZA");
 
        piezaRowSetPK.setDataSourceName("java:comp/env/jdbc/ALMACEN_ApacheDerby");
        piezaRowSetPK.setCommand("SELECT ALL ALMACEN.PIEZA.ID_PIEZA, ALMACEN.PIEZA.ID_PRODUCTO FROM ALMACEN.PIEZA");
        piezaRowSetPK.setTableName("PIEZA");
 
        getPiezaRowSetPK.setDataSourceName("java:comp/env/jdbc/ALMACEN_ApacheDerby");
        getPiezaRowSetPK.setCommand("SELECT ALL ALMACEN.PIEZA.ID_PIEZA, ALMACEN.PIEZA.ID_PRODUCTO FROM ALMACEN.PIEZA INNER JOIN ALMACEN.PRODUCTO ON ALMACEN.PIEZA.ID_PRODUCTO = ALMACEN.PRODUCTO.ID_PRODUCTO WHERE ALMACEN.PRODUCTO.PRODUCTO LIKE ?");
        getPiezaRowSetPK.setTableName("PIEZA");
 
 
The PK is formed by both, ID_PIEZA and ID_PRODUCTO being ID_PRODUCTO a foreign key.
 
Thanks in advance,
Jose Alvarez de Lara
[Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]

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