Hi,
Firstable I am going to introduce my code,
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.
My problem is the first time I select a Subcategoria from its
DDL. productosDD is a nested Producto DDL son when I select a Categoria and a Subcategoria the DDL Producto is loaded with a subset
of data of the table Producto. Well, when I select a Categoria and a Subcategoria it loads Producto and I get the first Item of the Producto DDL. Later I calculate the firstProductoId and idPieza and I hope that 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,
Code:
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,
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");
Where the PK is formed by both, ID_PIEZA and ID_PRODUCTO being ID_PRODUCTO a foreign key.
Thanks in advance,
Jose Alvarez de Lara