Validations can be triggered instantly without needing a button/link click using p:clientValidator.
<div class="card">
<h:form>
<h:panelGrid columns="4" cellpadding="7">
<p:outputLabel for="text" value="Text: (Change)"/>
<p:inputText id="text" value="#{validationView.text}" required="true">
<f:validateLength minimum="2" maximum="5"/>
<p:clientValidator/>
</p:inputText>
<p:message for="text" display="icon"/>
<h:outputText value="#{validationView.text}"/>
<p:outputLabel for="integer" value="Integer: (Keyup)"/>
<p:inputText id="integer" value="#{validationView.integer}">
<p:clientValidator event="keyup"/>
</p:inputText>
<p:message for="integer" display="icon"/>
<h:outputText value="#{validationView.integer}"/>
</h:panelGrid>
<p:commandButton value="Save" ajax="false" icon="pi pi-check" validateClient="true" styleClass="mt-3" />
</h:form>
</div>
package org.primefaces.showcase.view.csv;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import java.time.LocalDate;
import java.util.Date;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class ValidationView {
private String text;
private String color;
private String description;
private Integer integer;
private Double doubleNumber;
private Double money;
private String regexText;
private Date date;
private Date date2;
private Date date3;
private LocalDate localDate;
private LocalDate localDate2;
private LocalDate localDate3;
private String uiLibrary;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getInteger() {
return integer;
}
public void setInteger(Integer integer) {
this.integer = integer;
}
public Double getDoubleNumber() {
return doubleNumber;
}
public void setDoubleNumber(Double doubleNumber) {
this.doubleNumber = doubleNumber;
}
public Double getMoney() {
return money;
}
public void setMoney(Double money) {
this.money = money;
}
public String getRegexText() {
return regexText;
}
public void setRegexText(String regexText) {
this.regexText = regexText;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Date getDate2() {
return date2;
}
public void setDate2(Date date) {
this.date2 = date;
}
public Date getDate3() {
return date3;
}
public void setDate3(Date date) {
this.date3 = date;
}
public LocalDate getLocalDate() {
return localDate;
}
public void setLocalDate(LocalDate localDate) {
this.localDate = localDate;
}
public LocalDate getLocalDate2() {
return localDate2;
}
public void setLocalDate2(LocalDate localDate) {
this.localDate2 = localDate;
}
public LocalDate getLocalDate3() {
return localDate3;
}
public void setLocalDate3(LocalDate localDate) {
this.localDate3 = localDate;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getUiLibrary() {
return uiLibrary;
}
public void setUiLibrary(String uiLibrary) {
this.uiLibrary = uiLibrary;
}
public void modifyValues() {
setText("Mike");
setInteger(123);
}
public void modifyInteger() {
setInteger(456);
}
public void clearValues() {
setText(null);
setInteger(null);
setDoubleNumber(null);
}
}