h:form

HtmlForm is a UIForm component that renders a <form> element.

General Usage

In order to submit a form via Ajax, it is necessary to specify an f:ajax child tag inside of h:commandButton or h:commandLink.

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:h="http://xmlns.jcp.org/jsf/html"	xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

	<h:form>
		<h:messages globalOnly="true" layout="table" />
		<h:commandButton actionListener="#{formBackingBean.submit}"
			value="#{i18n['submit-and-re-render-page']}">
			<f:ajax execute="@form" render="@form" />
		</h:commandButton>
	</h:form>

</ui:composition>
@RequestScoped
@ManagedBean
public class FormBackingBean {

	public void submit() {

		FacesContext facesContext = FacesContext.getCurrentInstance();
		FacesMessage facesMessage = null;

		if (facesContext.getPartialViewContext().isAjaxRequest()) {
			facesMessage = new FacesMessage("The form was submitted via Ajax and re-rendered with updates to the DOM.");
		}
		else {
			facesMessage = new FacesMessage(
					"The form was submitted as a full page postback and the entire page was re-rendered.");
		}

		facesContext.addMessage(null, facesMessage);
	}
}
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20