package de.ivu.elect.presentation.gebietsbaum.form;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import org.apache.commons.lang3.StringUtils;

import de.ivu.elect.jee.faces.FacesMessageUtil;

public class NlGebietsnummerValidator implements Validator {
  @Override
  public void validate(FacesContext facesContext, UIComponent uiComponent, Object o) throws ValidatorException {
    if (o == null || StringUtils.isBlank(o.toString())) {
      return;
    }
    try {
      Long.parseLong(o.toString());
    } catch (Exception e) {
      throw new ValidatorException(FacesMessageUtil.createErrorMessage(facesContext, "nl.gebietsnummer.ungueltig", "nl.gebietsnummer.ungueltig"));
    }
  }
}
