Skip to main content

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

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

Hi,

Firstable I am going to introduce my code,

if (productoDataProviderPieza.getRowCount() > 0) {
try {
if (!getRequestBean1().getAction().equalsIgnoreCase("productosDD")) {
List productosDDDefaultOptions = (List) productosDD.getItems();
Iterator 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

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

Hi Jim,

I have posted in NetBeans forum yet, but have no answer. Even in the NetBeans mailing list.

I know it is a hard question. Maybe you know Dru Devore form java.net that has a blog about Visual Web Java Server Faces. I have asked him but have no answer.

You do some question but all refer to the process of execution of a JSF page: first preprocess() method, later the events methods, and finally the prerender() method. Now I have got it so may problem fall into a wrong code. That is the reason I have put in the thread all that code information, but maybe you are right, too many information.

Best regards,
Jose Alvarez de Lara

Jim Driscoll

On 7/4/09 12:35 AM, webtier@javadesktop.org wrote:

> You do some question but all refer to the process of execution of a

> JSF page: first preprocess()

> method, later the events methods, and finally the prerender() method.

Actually, those don't have to do with JSF, but rather, with the Rave
Framework (otherwise known as VWP) in Netbeans, that sits on top of JSF
: see here -

http://developers.sun.com/docs/jscreator/apis/appbase/com/sun/rave/web/u...

I did find a good dozen or so likely hits for prerender not being called
when I was doing a google search - sorry, since this isn't JSF, I don't
know that we can help you.

Jim

---------------------------------------------------------------------
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

There is a non clear paragraph. This is what I am meaning,

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.

Excuese my english,
Jose Alvarez de Lara

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

Hi folks,

I have been debugging the web app and everything is ok. So the problem is the order where the different methods are executed.

I mean, when I call productosDD_processValueChange(ValueChangeEvent event) {...} it gives me what I am waiting it does.

But when I call categoriasDD_processValueChange(ValueChangeEvent event) {...} or subcategoriasDD_processValueChange(ValueChangeEvent event) {...} methods, the preprender(){...} is executed after I call those methods but before... what? I do not know. But at the end I do not get what I was waiting.

So I feel ok if someone gives me the url of a good tutorial to understand all of it. The rest fall in my hands.

Thanks
Jose Alvarez de Lara

Jim Driscoll

If noone is answering you, it's probably because it was hard to
understand the question.

I don't know Visual JSF - that's a Netbeans thing, and there aren't tons
of people on this alias that know it - you may have better luck in
Netbeans forums.

But more specifically, you don't really give a lot of context, despite
providing a great deal of code. OK, you've got two valuechange events.
That are called where? By what? How does prerender fit in? Is that
a Visaul JSF thing?

The best questions are usually distilled down to less than 10 lines of
code - more than that, and it gets hard to see what's going on in all
the moving parts. That's also a good practice when you're debugging a
problem anyway - try to come up with a very short example that
illustrates your problem,and often the question answers itself.

I'm sorry I can't be of more help.

Jim

On 6/30/09 9:53 PM, webtier@javadesktop.org wrote:
> Hi folks,
>
> I have been debugging the web app and everything is ok. So the problem is the order where the different methods are executed.
>
> I mean, when I call productosDD_processValueChange(ValueChangeEvent event) {...} it gives me what I am waiting it does.
>
> But when I call categoriasDD_processValueChange(ValueChangeEvent event) {...} or subcategoriasDD_processValueChange(ValueChangeEvent event) {...} methods, the preprender(){...} is executed after I call those methods but before... what? I do not know. But at the end I do not get what I was waiting.
>
> So I feel ok if someone gives me the url of a good tutorial to understand all of it. The rest fall in my hands.
>
> Thanks
> Jose Alvarez de Lara
> [Message sent by forum member 'josealvarezdelara' (josealvarezdelara)]
>
> http://forums.java.net/jive/thread.jspa?messageID=353701
>
> ---------------------------------------------------------------------
> 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

Ed Burns

>>>>> On Wed, 01 Jul 2009 08:42:50 -0700, Jim Driscoll said:

JD> If noone is answering you, it's probably because it was hard to
JD> understand the question.

JD> I don't know Visual JSF - that's a Netbeans thing, and there aren't tons
JD> of people on this alias that know it - you may have better luck in
JD> Netbeans forums.

For what it's worth, the prerender() feature from Rave has been adopted
into JSF 2.0 via the SystemEvent facility. Please see [1] and [2].

[1] https://javaserverfaces.dev.java.net/nonav/docs/2.0/javadocs/javax/faces...

[2] https://javaserverfaces.dev.java.net/nonav/docs/2.0/javadocs/javax/faces...

--
| ed.burns@sun.com | office: 408 884 9519 OR x31640
| homepage: | http://ridingthecrest.com/

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

jyeary
Offline
Joined: 2004-07-20
Points: 0

I published an example of using the PreRenderComponentEvent on my blog to inject the component values prior to rendering. The code and example can be found here: JSF 2.x Component prerender() (PreRenderComponentEvent)