0

I have a class implementing Validator so i can define some custom validation rules for a property:

@Override
public void validate(FacesContext fc, UIComponent uic, Object obj) throws ValidatorException {
    Date date = (Date)obj;

    if(date == null) {
        FacesMessage msg = new FacesMessage("no value");
        throw new ValidatorException(msg);
    }
}

This custom error is not displayed when i submit an empty value:

<h:column>
    <h:inputText value="#{bean.date}" id="date">
        <f:facet name="date">Date</f:facet>
        <f:convertDateTime pattern="d.M.yyyy"/>
        <f:validator validatorId="dateValidator"/>
    </h:inputText>

    <h:message for="date" style="color:red"/>
</h:column>

So how can i validate if the date-field was even submitted(if it is not null)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Creative crypter
  • 1,348
  • 6
  • 30
  • 67
  • no its is not, because even if i submitte empty string and i check for empty string, no error msg is thrown.. – Creative crypter Jan 03 '17 at 16:18
  • 3
    By default, JSF does not validate a component if the value is empty. This behavior can be controlled with the context parameter javax.faces.VALIDATE_EMPTY_FIELDS. You can see more detail at http://stackoverflow.com/questions/22963442/jsf-custom-validator-not-working-when-input-is-null – tam nguyen Jan 03 '17 at 16:33

0 Answers0