JSF best practices : One form for the whole application or a few smaller forrms? -
what best practice in jsf , create 1 main <h:form>
in template example , put content inside or have few forms each parts, example if have 2 logical blocks of code on page should have wrapped these blocks in 2 separate forms ???
this overly broad question, , has nothing di jsf. question of html understanding , design.
if abstract away of jsf details, you'll find out rendered component plain html <form>
. recall specification, form is:
a section of document containing normal content, markup, special elements called controls (checkboxes, radio buttons, menus, etc.), , labels on controls. users "complete" form modifying controls (entering text, selecting menu items, etc.), before submitting form agent processing (e.g., web server, mail server, etc.)
so a whole form submitted server. in case of component-based framework, jsf, bound values of components populate backing beans submitted data, in case there no errors.
but data submitted? data within form. so, if have 1 global form means all unrelated pieces of information collected: user credentials, product choices, selection of preferences, etc. , done @ once. won't yield desired functionality, produce unexpected results.
the problem there mixing of concerns: 1 form contained non-related data was not designed submitted together. leaves one-form-per-user-interaction, 1 form user authentication/logout, form storing user preferences, yet 1 keeping product choices, etc. 1 global form leave nesting forms problem, taking time figure out.
regarding choice of put form, depending on logical separation: if have user login/logout on every page placed in master template. per-view forms put in template client. moreover, you'll find convenient put them side-by-side distinguish functionality.
also, form may alter expected behaviour. 1 final example: user choice of products. consider 2 cases.
the first one:
<h:form> <ui:repeat value="#{bean.purchasedproducts}" var="product"> <h:outputtext value=#{product.name}/> <h:inputtext value=#{product.quantity}/> <h:commandbutton value="change"/> </h:datatable> </h:form>
the second one:
<ui:repeat value="#{bean.purchasedproducts}" var="product"> <h:form> <h:outputtext value=#{product.name}/> <h:inputtext value=#{product.quantity}/> <h:commandbutton value="change"/> </h:form> </h:datatable>
while first example update all products, second 1 update only relevant product.
finally, there no 'best practice' or 'universal solution'. think it's best depart separation of concerns when designing html document.
and, yes, i'm voting close question.
Comments
Post a Comment