Bonjour je suis en train de mettre en place un formulaire avec Validator, je n'ai aucun message d'erreur, mais le message d'erreur de validation ne s'affiche pas, voici mon code :
mon formulaire :
ma Classe de validation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <h:inputText id="nom" size="30" value="#{contactManagedBean.nom}" maxlength="100"> <f:validator validatorId="nomValidator" /> </h:inputText> <h:message for="nom" class="red" />
mon fichier faces-config.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package validators; import beans.Objet; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.Validator; import javax.faces.validator.ValidatorException; /** * * @author FS-ESPRIMO */ public class NomValidator extends Objet implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { /*String nom=(String)value; if(empty(nom)) {*/ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Champ NOM vide.", "Champ NOM vide.")); // } } }
Je ne comprend pas pourquoi rien en s'affiche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <?xml version="1.0" encoding="UTF-8"?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd" version="2.1"> <validator> <validator-id>nomValidator</validator-id> <validator-class>validators.NomValidator</validator-class> </validator> </faces-config>
Merci pour votre aide.
Partager