Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JSF, Is there any benefit to splitting <h:form>s?

Tags:

html

jsf

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>?

like image 558
Ben Avatar asked Jun 01 '11 14:06

Ben


2 Answers

Yes, definitely each form needs to go in its own <h:form>.

  • You're not interested in the data of the other form. This also saves bandwidth and improves speed.
  • It would potentially unnecessarily trigger validators on the other form. This is bad for UX.

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.

like image 175
BalusC Avatar answered Nov 09 '22 05:11

BalusC


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.

like image 28
planetjones Avatar answered Nov 09 '22 05:11

planetjones