Home > Web development > JSF2: Nesting forms into each other — not a good idea

JSF2: Nesting forms into each other — not a good idea

January 23rd, 2011 Leave a comment Go to comments

This problem just cost me an hour worth of debugging: Clicking on a PrimeFaces <p:commandButton/> that was inside a composite component wouldn’t trigger the server-side action that was specified in the tag. Even more strange was that I had several of these buttons (created in a loop using <ui:repeat/>), and in the generated HTML, the first one wasn’t nested into an HTML form element, while the others were.

Finally, I found out that inside my composite component, I had nested the button into an <h:form/> tag; in the Facelet that used the composite, there was another form wrapped around it. This is apparently not such a good idea, because the HTTP protocol doesn’t allow multiple, nested forms (sure, since there is only a simple POST request involved). It’s a bit sad, though, that neither MyFaces 2.0.3, nor Mojarra 2.0.3 were able to catch this (rather simple) error and show a decent error message.

Categories: Web development Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.