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.VisitorService; 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 VisitorEmailExistValidator implements Validator { @Autowired VisitorService visitorService; @Override public void validate(FacesContext fc, UIComponent uic, Object o) throws ValidatorException { ResourceBundle rb = ResourceBundle.getBundle("ispok/pres/inter/ispok", fc.getViewRoot().getLocale()); if (!visitorService.emailAvailable(o.toString())) { throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, rb.getString("email_taken"), rb.getString("email_taken"))); } } }