Hobione's Weblog

Living & Breathing in Web 2.0 Era

How to set/add message to the FacesMessage? h:message

Question was asked at the OKC JUG presentation, how to send an error message from server to client.

Here is the code snippet:

<h:inputText id=”email” value=”#{user.email}” validator=#{user.validateEmail}/>
<h:message for=”email”/>

 public void validateEmail(FacesContext facesContext,UIComponent component, Object newValue) throws ValidatorException {
 String email = newValue.toString();
 if (email.equals("")) { // "".equals(email)
 FacesMessage message = new FacesMessage("Email address is required.");

Here is an another great questioned was answered by Jason Lee
A ValueChangeListener Question and Answer:

HH: How hack proof the required=”true”, can some one by pass it and update my model?
JDL: It’s processed server side, which helps, i think it’s safe to assume that the field will be non-null and ” ” != null


February 19, 2008 - Posted by | Java Server Faces


  1. Wow Cool !
    Super Man
    Nice Site

    Comment by ordersomabuyg | September 21, 2008 | Reply

  2. [eng] this is an error code should be the id not the name

    [esp] este codigo tiene un error debe ser por el id no por el name

    Comment by Samuel pichardo | April 17, 2009 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: