Skip to main content

Visual Web JSF and CRUD problem

3 replies [Last post]
josealvarezdelara
Offline
Joined: 2008-12-26
Points: 0

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
josealvarezdelara
Offline
Joined: 2008-12-26
Points: 0

Ok, I am going to take my question to NetBeans forum.
Thanks for the URL.

Best regards,
Jose Alvarez de Lara

Jim Driscoll

Since your question seems to be specific to Netbeans, have you
considered asking in a forum devoted to Netbeans?

http://forums.netbeans.org/

Jim

On 5/23/09 3:19 AM, webtier@javadesktop.org wrote:
> Hi,
>
> Going on with my web over NetBeans 6.5 Visual Web JSF, I had to make some changes to my data model because an initial wrong design. But I want to talk about Piezas.java.
>
> In Piezas.java I have three DDLs (Categorias, Subcategorias and Productos), three buttons (“New Pieza”, “Save Pieza”, and “Return to Index”) and a UIComponent Table that represents the selected Piezas.
>
> The relationships between database tables is as follow,
>
> Categoria
> PK: ID_CATEGORIA
>
> Subcategoria
> PK: ID_SUBCATEGORIA
> FK: ID_CATEGORIA
>
> Producto
> PK: ID_PRODUCTO
> FK: ID_CATEGORIA
> FK: ID_SUBCATEGORIA
>
> Pieza
> PK: ID_PIEZA
> FK: ID_PRODUCTO
>
> So my Piezas.java try CRUD based on this relationship. The DDLs Categorias and Subcategorias are set in a Virtual Form to set the DDL Productos. This works fine.
> And when I select some categoria or subcategoria that take me to a producto´s non value, the UIComponent Table Pieza looks empty: ok.
>
> I have three Virtual Forms, “categoria_subcategoria” to nest with the DDL Productos, “saveproducto” that save the new nested values on the DDL Productos on Participate and Submit the new pieza, and “save” to load the corresponding pieza values on the UIComponent Table Pieza once selected a new producto.
>
> What is my problem? When I try to add a new pieza, in the UIComponent Table Pieza appears the first row in the database table Pieza. I mean, there are two cases, there is no Producto and I cannot append any row, or there is a producto so when I append a new row it has to be from the entity of the selected Producto. Well, it is not. It is always from the entity of the first row of the database table Pieza.
>
> This is my code,
>
> @Override
> public void prerender() {
> if ((getRequestBean1().getAction()).equals("nothing")) {
> Object firstCategoriaId = null;
> Object firstSubcategoriaId = null;
> if ((categoriasDD.getSelected() == null)&& (subcategoriasDD.getSelected() == null)) {
> try {
> categoriaDataProviderPieza.cursorFirst();
> subcategoriaDataProviderPieza.cursorFirst();
> firstCategoriaId = categoriaDataProviderPieza.getValue("CATEGORIA.ID_CATEGORIA");
> firstSubcategoriaId = subcategoriaDataProviderPieza.getValue("SUBCATEGORIA.ID_SUBCATEGORIA");
> categoriasDD.setSelected(firstCategoriaId);
> subcategoriasDD.setSelected(firstSubcategoriaId);
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 1, firstCategoriaId);
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 2, firstSubcategoriaId);
> productoDataProviderPieza.refresh();
> } catch (Exception e) {
> error("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId);
> log("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId, e);
> }
> } else if ((categoriasDD.getSelected() != null)&& (subcategoriasDD.getSelected() == null)) {
> firstCategoriaId = categoriasDD.getSelected();
> try {
> subcategoriaDataProviderPieza.cursorFirst();
> getApplicationBean1().getProductoRowSet().setObject(
> 1, firstCategoriaId);
> firstSubcategoriaId = subcategoriaDataProviderPieza.getValue("SUBCATEGORIA.ID_SUBCATEGORIA");
> subcategoriasDD.setSelected(firstSubcategoriaId);
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 2, firstSubcategoriaId);
> productoDataProviderPieza.refresh();
> } catch (Exception e) {
> error("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId);
> log("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId, e);
> }
> } else if ((categoriasDD.getSelected() == null)&& (subcategoriasDD.getSelected() != null)) {
> try {
> categoriaDataProviderPieza.cursorFirst();
> firstCategoriaId = categoriaDataProviderPieza.getValue("CATEGORIA.ID_CATEGORIA");
> categoriasDD.setSelected(firstCategoriaId);
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 1, firstCategoriaId);
> firstSubcategoriaId = subcategoriasDD.getSelected();
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 2, firstSubcategoriaId);
> productoDataProviderPieza.refresh();
> } catch (Exception e) {
> error("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId);
> log("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId, e);
> }
> } else if ((categoriasDD.getSelected() != null)&& (subcategoriasDD.getSelected() != null)) {
> try {
> firstCategoriaId = categoriasDD.getSelected();
> firstSubcategoriaId = subcategoriasDD.getSelected();
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 1, firstCategoriaId);
> getApplicationBean1().getProductoRowSetPieza().setObject(
> 2, firstSubcategoriaId);
> productoDataProviderPieza.refresh();
> } catch (Exception e) {
> error("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId);
> log("Cannot switch to categoria/subcategoria " +
> firstCategoriaId + "/" + firstSubcategoriaId, e);
> }
> }
> RowKey[] rk = productoDataProviderPieza.getAllRows();
> if (rk.length> 0) {
> if (productosDD.getSelected() == null) {
> Object firstProductoId = null;
> try {
> productoDataProviderPieza.cursorFirst();
> firstProductoId = productoDataProviderPieza.getValue("PRODUCTO.ID_PRODUCTO");
> productosDD.setSelected(firstProductoId);
> getApplicationBean1().getPiezaRowSet().setObject(
> 1, firstProductoId);
> piezaDataProvider.refresh();
> } catch (Exception e) {
> error("Cannot switch to producto " +
> firstProductoId);
> log("Cannot switch to producto " +
> firstProductoId, e);
> }
> }
> } else {
> getRequestBean1().setMensaje("No hay Productos");
> }
> }
> getRequestBean1().setAction("nothing");
> }
>
>
> public void categoriasDD_processValueChange(ValueChangeEvent event) {
> Object selectedCategoriaId = categoriasDD.getSelected();
> try {
> productosDD.resetValue();
> categoriaDataProviderPieza.setCursorRow(
> categoriaDataProviderPieza.findFirst("CATEGORIA.ID_CATEGORIA",
> selectedCategoriaId));
> getApplicationBean1().getProductoRowSetPieza().setObject(1, selectedCategoriaId);
> productoDataProviderPieza.refresh();
> form1.discardSubmittedValues("saveproducto");
> } catch (Exception e) {
> error("Cannot switch to categoria " + selectedCategoriaId);
> log("Cannot switch to categoria " + selectedCategoriaId, e);
> }
> }
>
> public void subcategoriasDD_processValueChange(ValueChangeEvent event) {
> Object selectedSubcategoriaId = subcategoriasDD.getSelected();
> try {
> productosDD.resetValue();
> subcategoriaDataProviderPieza.setCursorRow(
> subcategoriaDataProviderPieza.findFirst("SUBCATEGORIA.ID_SUBCATEGORIA",
> selectedSubcategoriaId));
> getApplicationBean1().getProductoRowSetPieza().setObject(2, selectedSubcategoriaId);
> productoDataProviderPieza.refresh();
> form1.discardSubmittedValues("saveproducto");
> } catch (Exception e) {
> error("Cannot switch to subcategoria " + selectedSubcategoriaId);
> log("Cannot switch to subcategoria " + selectedSubcategoriaId, e);
> }
> }
>
> public void productosDD_processValueChange(ValueChangeEvent event) {
> RowKey[] rk = productoDataProviderPieza.getAllRows();
> if (rk.length> 0) {
> Object selectedProductoId = productosDD.getSelected();
> try {
> productoDataProviderPieza.setCursorRow(
> productoDataProviderPieza.findFirst("PRODUCTO.ID_PRODUCTO",
> selectedProductoId));
> getApplicationBean1().getPiezaRowSet().setObject(1, selectedProductoId);
> piezaDataProvider.refresh();
> form1.discardSubmittedValues("save");
> } catch (Exception e) {
> error("Cannot switch to producto " + selectedProductoId);
> log("Cannot switch to producto " + selectedProductoId, e);
> }
> } else {
> getRequestBean1().setMensaje("No hay Productos");
> }
> }
>
> public String add_action() {
> // TODO: Process the action. Return value is a navigation
> // case name where null will return to the same page.
> getRequestBean1().setAction("addpieza");
> RowKey[] rkArray = productoDataProviderPieza.getAllRows();
> if (rkArray.length> 0) {
> try {
> RowKey rk = piezaDataProvider.appendRow();
> piezaDataProvider.setCursorRow(rk);
>
> piezaDataProvider.setValue("PIEZA.ID_PIEZA", new Integer(0));
> piezaDataProvider.setValue("PIEZA.ID_PRODUCTO", productosDD.getSelected());
> } catch (Exception ex) {
> log("Error Description", ex);
> error(ex.getMessage());
> }
> } else {
> getRequestBean1().setMensaje("No hay Productos");
> }
> return null;
> }
>
> It was taking me two weeks and I have not any idea about the solution.
> Please help.
>
> Best regards,
> Jose Alvarez de Lara
> [Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]
>
> http://forums.java.net/jive/thread.jspa?messageID=347398
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

josealvarezdelara
Offline
Joined: 2008-12-26
Points: 0

My english is not as good as I would like and the question answered or ananswered is taking me to a confusion.