package de.ivu.elect.business.internet.control;

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

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

public class InternetPreasentationTypValidator implements Validator {

  @Override
  public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

    if (value != null) {
      if (!BeanManagerUtil.getBeanByClass(InternetPreasentationTypKonfigrationWertGeaendertEventListener.class).getSupportedTypen()
          .contains(value.toString())) {
        throw new ValidatorException(FacesMessageUtil.createErrorMessage(context, "internet.typ.not.supported", "internet.typ.not.supported"));
      }
    }

  }
}
