Validator method

xhtml:

<h:inputText value="#{myBean.inputValue}" validator="#{myBean.validateInput}" />

Java:

public void validateInput(FacesContext context, UIComponent inputComponent, Object value) {
  String textValue = (String) value;
    
  // validate value ...
    
  if(!valid) {
    throw new ValidatorException(new FacesMessage("Text not valid"));  
  }
}

Custom converter

xhtml:

<h:inputText value="#{myBean.inputValue}">
  <f:converter converterId="com.example.MyConverter"/>
</h:inputText>

Java:

@FacesConverter("com.example.MyConverter")
public class TimeConverter implements Converter {
  
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value) {
    if(value == null) {
      return null;
    }
  
    // validate value ...
  
    if (valid) {
      return value;
    }
  
    FacesMessage msg = new FacesMessage("Text not valid");
    msg.setSeverity(FacesMessage.SEVERITY_ERROR);
    throw new ConverterException(msg);
  }
  
  @Override
  public String getAsString(FacesContext context, UIComponent component, Object value) {
    return (String) value;
  } 
}