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
-
Archives
- November 2009 (1)
- July 2009 (1)
- June 2009 (5)
- May 2009 (2)
- April 2009 (4)
- March 2009 (2)
- January 2009 (3)
- December 2008 (1)
- November 2008 (2)
- October 2008 (1)
- September 2008 (3)
- August 2008 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS