Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ispok.valid; import ispok.service.EmployeeService; import java.util.ResourceBundle; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.Validator; import javax.faces.validator.ValidatorException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; /** * * @author Jan Mucha <j.mucha@seznam.cz> */ @Configurable @FacesValidator public class EmployeeValidator implements Validator { @Autowired EmployeeService employeeService; @Override public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException { ResourceBundle rb = ResourceBundle.getBundle("ispok/pres/inter/ispok", fc.getViewRoot().getLocale()); if (employeeService.employeeExist(o.toString())) { throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, rb.getString("employee_invalid_exist"), rb.getString("employee_invalid_exist"))); } } }