File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Number of <h:form > tags on a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Number of <h:form > tags on a page" Watch "Number of <h:form > tags on a page" New topic

Number of <h:form > tags on a page

Scott Stephens

Joined: Jun 25, 2011
Posts: 23

I am having a problem that only one of the <h:commandButton> tags fire when I have two <h:form> tags on the page. Is it allowed to have more than one <h:form> tag on the page. The Html from two forms is rendered, however the action="backing bean" isn't fired. I could use some help here.
Using JSF 2.0 with MyFaces and hibernate 3.2

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17282

You can have as many h:form elements on a page as you can endure. I do this all the time.

The rules are the same as for straight HTML forms:

1. FORMs cannot be nested nor can they overlap.

2. ONLY the data in the form that contains the SUBMIT button (or other control) that fired off the request will be posted back to the server.

And for JSF:

3. If ANY control value on the submitted form fails validation, NONE of the backing bean properties will get updated AND the action method and/or listeners will not be fired. When in doubt, add an h:messages tag to your page to display any possible "validation failed" messages.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Number of <h:form > tags on a page
It's not a secret anymore!