Friday, June 13, 2008

JSF messages

Detail or Summary
showDetail="true" => "javax.faces.component.UIInput.REQUIRED_detail"
showSummary="true" => "javax.faces.component.UIInput.REQUIRED"
For example
<h:message for="lastName" errorClass="errorClass"
showSummary="true" showDetail="false"/>
Default, showDetail="true", showSummary="false".

Look up Convention
<h:inputText ... required="true" ..."/>
javax.faces.component.UIInput.REQUIRED

This is message for converter.
javax.faces.converter.IntegerConverter.INTEGER

This is message for validator
javax.faces.validator.LengthValidator.MINIMUM
Message for custom converter
public class xxxConverter implements Converter {

public Object getAsObject(FacesContext facesContext, UIComponent component,
String value) {
//validation
if ( ... ) {
throw new ConverterException(new FacesMessage(
FacesMessage.SEVERITY_ERROR, "summary message", "detail message"));
}
...
}
...

Message for custom validator
public class xxxValidator implements Validator {
public void validate(FacesContext context,
UIComponent component,
Object obj)
throws ValidatorException {
//validation
if(...)
throw new ValidatorException(new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"summary message", "detail message"));
}...
}
}

No comments:

Post a Comment