If you use Hibernate validators then it could go with @mabi's solution, which is also explained here. Otherwise, you could also write your own JSF validator:
@FacesValidator
public class NoBlankSpaceValidator implements Validator{
@Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
//Check if user has typed only blank spaces
if(value.toString().trim().isEmpty()){
FacesMessage msg =
new FacesMessage("Incorrect input provided",
"The input must provide some meaningful character");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(msg);
}
}
}
And use it as:
<h:inputText value="#{userController.user.firstName}"
required="true" requiredMessage="#{bundle.common_error_empty_value}"
validator="noBlankSpaceValidator"/>
See also: