Client Side Validation Framework is integrated with Bean Validation Specification.
<div class="card">
<h:form>
<p:messages/>
<h:panelGrid columns="4" cellpadding="7" styleClass="mb-3">
<p:outputLabel for="@next" value="Given Name: (@Size(min=2,max=5))"/>
<p:inputText value="#{beanValidationView.name}" label="Given Name"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.name}"/>
<p:outputLabel for="@next" value="Surname: (@NotBlank)"/>
<p:inputText value="#{beanValidationView.notBlank}" label="Surname" />
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.notBlank}"/>
<p:outputLabel for="@next" value="Address: (@NotEmpty)"/>
<p:inputText value="#{beanValidationView.notEmpty}" label="Address"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.notEmpty}"/>
<p:outputLabel for="@next" value="Age: (@Min(10) @Max(20))"/>
<p:inputText value="#{beanValidationView.age}" label="Age"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.age}"/>
<p:outputLabel for="@next" value="Amount: (@DecimalMax('99.9'))"/>
<p:inputText value="#{beanValidationView.amount}" label="Amount"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.amount}"/>
<p:outputLabel for="@next" value="Amount: (@Digits(integer=3,fraction=2))"/>
<p:inputText value="#{beanValidationView.amount2}" label="Amount 2"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.amount2}"/>
<p:outputLabel for="@next" value="Pattern: (@Pattern(regexp='^[-+]?\\d+$'))"/>
<p:inputText value="#{beanValidationView.pattern}" label="pattern"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.pattern}"/>
<p:outputLabel for="@next" value="Assert: (@AssertTrue)"/>
<p:selectBooleanCheckbox value="#{beanValidationView.checked}"/>
<p:message for="@previous"/>
<h:outputText/>
<p:outputLabel for="@next" value="Date (@Past)"/>
<p:inputText value="#{beanValidationView.pastDate}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</p:inputText>
<p:message for="@previous"/>
<h:outputText/>
<p:outputLabel for="@next" value="Time (@PastOrPresent)"/>
<p:inputText value="#{beanValidationView.pastOrPresentDate}">
<f:convertDateTime pattern="HH:mm:ss"/>
</p:inputText>
<p:message for="@previous"/>
<h:outputText/>
<p:outputLabel for="@next" value="Date (@Future)"/>
<p:inputText value="#{beanValidationView.futureDate}">
<f:convertDateTime pattern="MM/dd/yyyy"/>
</p:inputText>
<p:message for="@previous"/>
<h:outputText/>
<p:outputLabel for="@next" value="DateTime (@FutureOrPresent)"/>
<p:inputText value="#{beanValidationView.futureOrPresent}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss"/>
</p:inputText>
<p:message for="@previous"/>
<h:outputText/>
<p:outputLabel for="@next" value="Negative: (@Negative)"/>
<p:inputText value="#{beanValidationView.negative}" label="Negative"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.negative}"/>
<p:outputLabel for="@next" value="Negative/Zero: (@NegativeOrZero)"/>
<p:inputText value="#{beanValidationView.negativeOrZero}" label="Negative"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.negativeOrZero}"/>
<p:outputLabel for="@next" value="Positive: (@Positive)"/>
<p:inputText value="#{beanValidationView.positive}" label="Positive"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.positive}"/>
<p:outputLabel for="@next" value="Positive/Zero: (@PositiveOrZero)"/>
<p:inputText value="#{beanValidationView.positiveOrZero}" label="Positive"/>
<p:message for="@previous"/>
<h:outputText value="#{beanValidationView.positiveOrZero}"/>
<p:outputLabel for="@next" value="Radio Input"/>
<p:selectOneRadio value="#{beanValidationView.bool}">
<f:selectItem itemValue="#{true}" itemLabel="True"/>
<f:selectItem itemValue="#{false}" itemLabel="False"/>
</p:selectOneRadio>
<p:message for="@previous"/>
<h:outputText/>
</h:panelGrid>
<p:commandButton value="Save" ajax="false" icon="pi pi-check" validateClient="true" styleClass="mr-3" />
<p:commandButton value="Save with disabled CSV" ajax="false" icon="pi pi-check" />
</h:form>
</div>
@Named
@RequestScoped
public class BeanValidationView {
@Size(min = 2, max = 5)
private String name;
@Min(10)
@Max(20)
private Integer age;
@DecimalMax(value = "99.9", message = "Shold not exceed 99.9")
private Double amount;
@Digits(integer = 3, fraction = 2)
private Double amount2;
@AssertTrue
private boolean checked;
@Past
private Date pastDate;
@PastOrPresent
private Date pastOrPresentDate;
@Future
private Date futureDate;
@FutureOrPresent
private Date futureOrPresent;
@Negative
private Integer negative;
@NegativeOrZero
private Integer negativeOrZero;
@Positive
private Integer positive;
@PositiveOrZero
private Integer positiveOrZero;
@Pattern(regexp = "^[-+]?\\d+$")
private String pattern;
@NotNull
private Boolean bool;
@NotBlank
private String notBlank;
@NotEmpty
private String notEmpty;
@Email
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Double getAmount2() {
return amount2;
}
public void setAmount2(Double amount2) {
this.amount2 = amount2;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public Date getPastDate() {
return pastDate;
}
public void setPastDate(Date pastDate) {
this.pastDate = pastDate;
}
public Date getFutureDate() {
return futureDate;
}
public void setFutureDate(Date futureDate) {
this.futureDate = futureDate;
}
public String getPattern() {
return pattern;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
public Boolean getBool() {
return bool;
}
public void setBool(Boolean bool) {
this.bool = bool;
}
public String getNotBlank() {
return notBlank;
}
public void setNotBlank(String notBlank) {
this.notBlank = notBlank;
}
public String getNotEmpty() {
return notEmpty;
}
public void setNotEmpty(String notEmpty) {
this.notEmpty = notEmpty;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getPastOrPresentDate() {
return pastOrPresentDate;
}
public void setPastOrPresentDate(Date pastOrPresentDate) {
this.pastOrPresentDate = pastOrPresentDate;
}
public Date getFutureOrPresent() {
return futureOrPresent;
}
public void setFutureOrPresent(Date futureOrPresent) {
this.futureOrPresent = futureOrPresent;
}
public Integer getNegative() {
return negative;
}
public void setNegative(Integer negative) {
this.negative = negative;
}
public Integer getNegativeOrZero() {
return negativeOrZero;
}
public void setNegativeOrZero(Integer negativeOrZero) {
this.negativeOrZero = negativeOrZero;
}
public Integer getPositive() {
return positive;
}
public void setPositive(Integer positive) {
this.positive = positive;
}
public Integer getPositiveOrZero() {
return positiveOrZero;
}
public void setPositiveOrZero(Integer positiveOrZero) {
this.positiveOrZero = positiveOrZero;
}
}