JSF Showcase

f:validateBean

The f:validateBean Facelet tag takes advantage of Bean Validation annotations on Java Bean properties.

General Usage



Source Code

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

	<h:form>
		<label class="control-label">#{i18n['please-enter-your-email']}</label>
		<h:inputText id="email" value="#{validationModelBean.email}"
			label="#{i18n['validate-email-label']}">
			<f:validateBean />
		</h:inputText>
		<br />
		<h:message for="email" />
		<hr />
		<h:commandButton value="#{i18n['submit']}">
			<f:ajax	execute="@form" render="@form" />
		</h:commandButton>
		<h:outputText value="#{validationModelBean.email}" />
	</h:form>

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

	@Pattern(regexp = ".+[@].+[.].+")
	private String email;
	private Double doubleNumber;
	private Long longNumber;
	private String otherText;

	public Double getDoubleNumber() {
		return doubleNumber;
	}

	public String getEmail() {
		return email;
	}

	public Long getLongNumber() {
		return longNumber;
	}

	public String getOtherText() {
		return otherText;
	}

	public void setDoubleNumber(Double doubleNumber) {
		this.doubleNumber = doubleNumber;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setLongNumber(Long longNumber) {
		this.longNumber = longNumber;
	}

	public void setOtherText(String otherText) {
		this.otherText = otherText;
	}
}
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14