What exactly does JSF h:form tag

依然范特西╮ 提交于 2020-01-07 06:58:26

问题


Could someone explain in own words how exactly h:form works and what is it good for ? I am completely new to JSF and I noticed strange behaviour. Let's say I have a button which redirect me to home page like this:

h:commandButton value="back" action="home?faces-redirect=true"

When I don't wrap this button into h:form tag button simply doesn't work... What exactly do h:form behind the scene ? I have read official documentation but I don't feel that I know how it works...

Thanks


回答1:


It places <form /> HTML tag into rendered result (pure HTML sent to client). The benefit of this is that all elements inside <h:form /> can use POST (or GET eventually) request to send informations to the server.

The <h:commandButton /> uses this kind of request so it works only in <h:form />. So do other form elements like <h:inputText /> etc. These elements need to be contained in <h:form /> so information entered by user can be sent to the server and processed.

Also, some other components that don't seem to be form elements also need to use <h:form /> because they send information to the server. An example of such component may be PrimeFaces (extension library of JSF) data table (<p:dataTable />).



来源:https://stackoverflow.com/questions/31534390/what-exactly-does-jsf-hform-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!