In non-Ajaxified JSF, there is no point in having h:commandButton unless it is within h:form. But with f:ajax around, a standalone h:commandButton now makes sense. After all, I use <input type="button".../> with "normal" Ajax apps all the time, frequently without a form. And doing so is most definitely allowed by the xhtml spec.
So, I looked in the spec (JSF_20090506.pdf) and the online API (
https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/h/commandButton.html ). In neither case could I see where it said one way or the other, but I could have easily missed it.
Next, I tried it. The first example I tried worked fine with no h:form. (Pushing the button caused a re-render of a simple h:outputText showing a random number.) But then I tried what appeared to be a very similar example, and I got a JavaScript error from line 1623-1626 of jsf-uncompressed.js:
1623 var form = getForm(element);
1624 if (!form) {
1625 throw new Error("jsf.ajax.request: Method must be called within a form");
1626 }
So, is there or is there not a requirement that h:commandButton or f:ajax be nested within h:form? And where in the spec does it say so?
Thanks!
- Marty
http://www.coreservlets.com
[Message sent by forum member 'martyhall' (hall_at_coreservlets.com)]
http://forums.java.net/jive/thread.jspa?messageID=366218