<h:message />
<h:messages />
Code language: HTML, XML (xml)<h:messages globalOnly="true" />
Code language: HTML, XML (xml)...
<h:inputText id="userName" value="#{userBean.userName}" />
<h:message for="userName" />
...
Code language: HTML, XML (xml)<h:message for="userName" showSummary="true"/>
<h:messages showDetail="true"/>
Code language: HTML, XML (xml)<h:inputText id="Username" value="#{UserBean.userName}">
 <f:validateLength minimum="6" maximum="15"/>
</h:inputText>
....
<h:inputText id="Age" value="#{UserBean.age}">
 <f:validateLongRange minimum="1" maximum="120"/>
</h:inputText>
Code language: HTML, XML (xml)public void <METHOD_NAME> (FacesContext context, UIComponent component, Object value) { .. }
Code language: Java (java)<h:inputText value="#{userBean.name}" validator="#{userBean.checkUsername}">
</h:inputText>
Code language: HTML, XML (xml)import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
...
...
public void validate(FacesContext context, UIComponent component, Object value)
  throws ValidatorException {
}
Code language: Java (java)<validator>
 <validator-id>emailValidator</validator-id>
 <validator-class>net.viralpatel.jsf.helloworld.EmailValidator</validator-class>
</validator>
Code language: HTML, XML (xml)<h:inputText id="Email" value="#{userBean.email}" required="true">
 <f:validator validatorId="emailValidator" />
</h:inputText>
Code language: HTML, XML (xml)package net.viralpatel.jsf.helloworld;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
public class EmailValidator implements Validator{
 public void validate(FacesContext context, UIComponent component, Object value)
   throws ValidatorException {
  
  String email = (String) value;
  
  if(!email.contains("@")) {
   FacesMessage message = new FacesMessage();
   message.setSeverity(FacesMessage.SEVERITY_ERROR);
   message.setSummary("Email is not valid.");
   message.setDetail("Email is not valid.");
   context.addMessage("userForm:Email", message);
   throw new ValidatorException(message);
  }
 }
}
Code language: Java (java)Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…
Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…
Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…
1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…
GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…
1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…
View Comments
Hi,
Useful article buddy. It would really help if you can put up a post on integrating Apache Shale with JSF. Thanks. Keep up the good work!
Cheers,
John
What's up? Been reading for a while and just decided to write!
Short but very well done tutorial. Thanxs
THANKS. Very good
Very useful and to the point hints in this tutorial. Thanks for this share.
Thanks for the article. Real good one.
Nice work , keep it up ..
thanks buddy.
Hi how to generate popup while displaying validation error. for example for inputtext required=true if i skip and press submit button i want to display h:message in popup is that possible in jsf2.0 . could u repsond this .
Thanks inadvance.
Thanks for the tutorial. Very helpful for the beginners :)
thx 4 the tutoial :))
Thanks , very good for the beginner :D