webtier@glassfish.java.net

Re: [webtier] JSF 2 ajax and forms nested in data table problem

From: Jim Driscoll <Jim.Driscoll_at_Sun.COM>
Date: Fri, 11 Dec 2009 12:28:26 -0800

Change your commandButton to instead say:

[b] <h:commandButton
                             id="addToCart" value="Add to cart"
actionListener="#{itemBean.addToCart}">
                             <f:ajax execute="@form" render="@form"/>
                         </h:commandButton>
[/b]
And it'll work fine.

What you were doing wrong: The ID's you were using didn't actually
appear anywhere in the page. Also, it's probably bad practice to use an
action event for Ajax when you really just want an action listener
(though that didn't matter here, it might later).

f:ajax uses relative id's (instead of "@form", I could have also said
"addToCartForm"). jsf.ajax.request must use absolute ids - that means
that they appear somewhere in the rendered page, and in the case of
tables, that means "items:0:addToCartForm:addToCart", which is a pain,
hence the use of the f:ajax tag.

What Mojarra was probably doing wrong: We currently don't report an
error, or even log a warning, if you do that. I've filed a bug to track
this issue:
https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1452

But it's tricky exactly what we should do here - Log a warning?
complete the part we can, and also send a client error? I don't know,
I'll have to think about it.

Jim