0
votes

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
I suggest to take a step back and learn some basic HTML first. E.g. htmldog.com/guides/html/beginner/forms JSF is in the context of this question just a HTML code generator. Rightclick, view source, etc in browser.BalusC

1 Answers

2
votes

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 />).