A general best-practices question.
Say I have a search box and a web form on the same page.
Is there any benefit to splitting the <h:form>
so they each get their own?
Or put them all in the same <h:form>
?
Yes, definitely each form needs to go in its own <h:form>
.
Note that you cannot nest forms. This is disallowed as per HTML spec, so also in JSF as all it basically does is generating a bunch of HTML.
If they share a single form the data for each will get submitted together. This doesn't sound right. The question could be rephrased to basic HTML terms i.e. should forms with distinct purposes and distinct submission buttons be in their own elements. The answer is yes.
I think the main advantage of splitting is separation of concerns, so one form with a distinct purpose is not tied to another one. And the processing code on the server can be separate, so you don't have to write conditional statements to change validations, etc. A separate controller could handle each of the forms if they are separate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With