ValidatorId未调用且未显示任何错误消息

时间:2014-11-30 18:46:42

标签: spring jsf jsf-2

我已经实现了一个类来验证它应该是唯一的字段,当我放置数据库中存在的值时,没有任何事情发生。你能帮助我吗!!!! 这是我的代码: 观点:

<h:outputText  value="Libelle :"></h:outputText>
                                <h:inputText value="#{restaurantsManage.libelle}"
                    id="libelle" required="true" requiredMessage="adresse est requise">

                   <f:ajax event="blur" render="libelleMessage" />
                                    <f:validator validatorId="libelleValidator" />
                                </h:inputText>
                                <h:message id="libelleMessage" for="libelle"  />  

这是Validator类:

@FacesValidator(value="libelleValidator")
public class LibelleValidator implements Validator {

    private static final String LIBELLE_EXISTE = "Ce libellé existe deja";


      @Autowired
    private IRestaurantService restaurantService;

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

        String libelle = (String) value;
        try { 
            if ( restaurantService.ExisteRestaurant(libelle)==false ) {

                throw new ValidatorException(
                        new FacesMessage( FacesMessage.SEVERITY_ERROR, LIBELLE_EXISTE, null ) );
            }
        } catch ( Exception e ) {

            FacesMessage message = new FacesMessage( FacesMessage.SEVERITY_ERROR, e.getMessage(), null );
            FacesContext facesContext = FacesContext.getCurrentInstance();
            facesContext.addMessage( component.getClientId( facesContext ), message );
        }
    }
}

0 个答案:

没有答案