package com.llgc; 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; @FacesValidator("com.llgc.BeanPersonneValidatorTaille") public class BeanPersonneValidatorTaille implements Validator { @Override public void validate (FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException { int taille; try { taille = Integer.parseInt (arg2.toString ()); } catch (NumberFormatException e) { FacesMessage msg = new FacesMessage ("Échec lorg de la vérification de la taille.", arg2.toString () + " n'est pas un nombre."); msg.setSeverity (FacesMessage.SEVERITY_ERROR); throw new ValidatorException (msg); } if (taille < 30 || taille > 250) { FacesMessage msg = new FacesMessage ("Échec lorg de la vérification de la taille.", "La taille doit être comprise entre 30 et 250 cm."); msg.setSeverity (FacesMessage.SEVERITY_ERROR); throw new ValidatorException (msg); } } }