开发者

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

开发者 https://www.devze.com 2023-03-09 15:06 出处:网络
A general best-practices question. Say I h开发者_如何学Cave a search box and a web form on the same page.

A general best-practices question.

Say I h开发者_如何学Cave 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>.

  • 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.


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.


The others are right, but I'd like to add that using AJAX you can do a partial form submit. You can specify which input components should be send and processed server side.

0

精彩评论

暂无评论...
验证码 换一张
取 消