问题
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