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)
 ((UIInput)component).setValid(false);
 FacesMessage message = new FacesMessage("Email address is required.");
 facesContext.addMessage(component.getClientId(facesContext),message);
 }
 }

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 HobiOne | Java Server Faces | | 2 Comments

Glassfish jdbc connection pool or jdbc datasource setup

February 19, 2008 Posted by HobiOne | GlassFish | | No Comments Yet