IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

[Struts Validator] probleme affichage des erreurs


Sujet :

Struts 1 Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 29
    Points : 19
    Points
    19
    Par défaut [Struts Validator] probleme affichage des erreurs
    Voila je voudrais valider un formulaire cote client grace a Validator.
    Tout fonctionne mise a part que les messages d erreurs ne sont pas affichees. Quand je laisse login ou password vide il se contente de recharger la page....
    Je vois pas ou est mon erreur alors si quelqun a une idee...
    Merci d avance

    validation.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
    25
     
    <?xml version="1.0" encoding="ISO-8859-1" ?>
     
    <!DOCTYPE form-validation PUBLIC
              "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
              "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
     
    <form-validation>
     
        <formset>
            <!-- Validation pour le formulaire d'authentification -->
            <form name="authentificationbean">
                <field
    				property="login"
                    depends="required">
                        <arg0 key="personne.authentification.login.vide"/>
                </field>
                <field
                    property="password"
                    depends="required">
                        <arg0 key="personne.authentification.password.vide"/>
                </field>
            </form>
        </formset>
    </form-validation>
    ressource.properties:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    errors.header=<ul>
    errors.footer=</ul>
    personne.authentification.login.vide=<font color="red"><li>Nom d'utilisateur manquant</li></font>
    personne.authentification.password.vide=<font color="red"><li>Mot de passe manquant</li></font>
    formulaire:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html>
    	<meta http-equiv="pragma" content="no-cache">
    	<head>
    	<title>Personne - authentification</title>
    	</head>
    	<body>
    		<center>
    			<table width="100%" align="center" valign="center">
    				<tr>
    					<td width="10%">
    						<img src="/srv/vues/images/logo-emn.gif">
    					</td>
    					<td align="center">
    						<h2><font color="navy">Système de réservation des véhicules de l'EMN</font></h2>
    					</td>
    					<td width="10%">
    					</td>
    				</tr>
    			</table>			
    			<hr>
    			<br>
    			<br>
    			<br>
    			<html:form action="/authentification">
    				<table>	
    					<tr>
    						<td align="center"><font color="navy">Nom d'utilisateur</font></td>
    						<td align="center"><html:text property="login" size="20" style="color: navy"/></td>
    					</tr>
    					<tr>
    						<td align="center"><font color="navy">Mot de passe</font></td>
    						<td align="center"><html:password property="password" size="20" style="color: navy"/></td>
    					</tr>
    				<tr>
    				</table>
    				<table>
    					<tr>
    						<td><html:submit value="Login" style="color: navy"/></td>
    					</tr>
    				</table>
    				<table height="80">
    					<tr>
    						<td width=300 height=80 align=center><html:errors/></td>
    					</tr>
    				</table>
    				<br>
    				<br>
    				<table border=1 cellspacing=0 cellpadding=20>
    					<tr>
    						<td height=20 align=center><font color="navy" size="2">Ce site est optimisé pour une utilisation en 1024*768 avec les navigateurs Mozilla 1.7, FireFox, Netscape 7.0  et Internet Explorer 6.0</font></td>
    					</tr>
    				</table>
    			</html:form>
    		</center>
    	</body>
    </html>
    Struts-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
     
     
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
     
    <form-beans>
    	<form-bean name="authentificationbean" type="beans.AuthentificationBean"/>
    	<form-bean name="reservationbean" type="beans.ReservationBean"/>
    	<form-bean name="substitutbean" type="beans.SubstitutBean"/>
    	<form-bean name="vehiculebean" type="beans.VehiculeBean"/>
    </form-beans>
     
     
    //action-mapping...
     
     
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    	<set-property value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" property="pathnames"/>
    </plug-in>
     
    </struts-config>

  2. #2
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Tes beans doivent étendre ValidatorForm , est ce le cas ?
    De plus l'action qui gère ce form ne doit pas avoir de propriété du genre validate="false"

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 29
    Points : 19
    Points
    19
    Par défaut
    Mes beans étende bien ValidateForm et la propriete validate est a true.
    Ce qui me mets encore plus dans le doute (ou peut etre que c'est de la que viens le probleme...) c'est que la validation etait gerer avant avec la methode validate du bean ( supprimer maintenat) et les messages d'erreur s afficher...
    Voici mon bean a tout hasard:
    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
    25
    26
    27
    28
    29
     
    package beans;
     
    import org.apache.struts.validator.ValidatorForm;
     
    public class AuthentificationBean extends ValidatorForm
    {
    	private String login = null;
    	private String password = null;
     
    	public String getLogin() 
    	{
    		return this.login;
    	}
    	public void setLogin(String login) 
    	{
    		this.login = login;
    	}
     
    	public String getPassword() 
    	{
    		return this.password;
    	}
     
    	public void setPassword(String password)
    	{
    		this.password = password;
    	}
    }
    et l'action mapping:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    	<action
    	path="/authentification"
    	name="authentificationbean"
    	validate="true"
    	input="/vues/formulaire.authentification.jsp" 
    	scope="session"
    	type="actions.AuthentificationAction">
    		<forward name="reponse_hotesse" path="/vues/accueil.hotesse.jsp"/>
    		<forward name="reponse_administrateur" path="/vues/accueil.administrateur.jsp"/>
    		<forward name="reponse_chef_service" path="/vues/accueil.chef.service.jsp"/>
    		<forward name="reponse_demandeur" path="/vues/accueil.demandeur.jsp"/>
    		<forward name="erreurlogin" path="/vues/formulaire.authentification.jsp"/>
    	</action>

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 29
    Points : 19
    Points
    19
    Par défaut
    ok je viens de tenter un truc dans ressource.properties j ai ajouter cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    errors.required={0} is required.
    et la le message "# Nom d'utilisateur manquant
    is required" s affiche...

    ok comme ca ca marche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    errors.header=<ul>
    errors.footer=</ul>
    errors.required={0}
    personne.authentification.login.vide=<font color="red"><li>Nom d'utilisateur manquant</li></font>
    personne.authentification.password.vide=<font color="red"><li>Mot de passe manquant</li></font>
    Mais ca me parait etre du bricolage, il existe pas une meilleure methode?

  5. #5
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    arf c'est clair si tu n'avais pas saisi les messages il devait pas être contant.
    Pour info dans le struts-config.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
      <message-resources parameter="net.zekey.presentation.struts.ApplicationResources" null="false"  />
    Remarque le null="false", quand tu as oublié un texte, il te l'affiche quand même sous la forme: fr.toto.tutu


    Pour le reste
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    errors.required={0} is required.
    il va remplacer {0} par le parametre manquant que tu as definie dans le validation.xml. Donc dedans il faut pas mettre un truc du genre: personne.authentification.login.vide mais plutot personne.authentification.login.
    Comme ca si en plus du required tu lui donnes une maxLenght, il utilisera le même

    [/img]

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 29
    Points : 19
    Points
    19
    Par défaut
    ok d'ac merci bien...
    Juste une derniere question :
    Cette verification s'effectue elle cote client ou cote serveur ?

  7. #7
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Par défaut du coté du serveur, mais si tu rajoutes un tag du <html:javascript form="" /> dans ta jsp, cela le fera aussi coté client.

    Si ca marche un petit tag résolu stp...

  8. #8
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 29
    Points : 19
    Points
    19
    Par défaut
    Ca marche même trés bien...
    Je mets les codes pour ceux que ca interresse de valider un formulaire cote client.
    le formulaire:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <html>
    	<meta http-equiv="pragma" content="no-cache">
    	<head>
    		<title>Personne - authentification</title>
    		<html:javascript formName="authentificationbean" />
    	</head>
    	<body>
    		<center>
    			<table width="100%" align="center" valign="center">
    				<tr>
    					<td width="10%">
    						<img src="/srv/vues/images/logo-emn.gif">
    					</td>
    					<td align="center">
    						<h2><font color="navy">Système de réservation des véhicules de l'EMN</font></h2>
    					</td>
    					<td width="10%">
    					</td>
    				</tr>
    			</table>			
    			<hr>
    			<br>
    			<br>
    			<br>
    			<html:form action="/authentification" focus="login" onsubmit="return validateauthentificationbean(this);">
    				<table>	
    					<tr>
    						<td align="center"><font color="navy">Nom d'utilisateur</font></td>
    						<td align="center"><html:text property="login" size="20" style="color: navy"/></td>
    					</tr>
    					<tr>
    						<td align="center"><font color="navy">Mot de passe</font></td>
    						<td align="center"><html:password property="password" size="20" style="color: navy"/></td>
    					</tr>
    				<tr>
    				</table>
    				<table>
    					<tr>
    						<td><html:submit property="action" style="color: navy"/></td>
    					</tr>
    				</table>
    				<table height="80">
    					<tr>
    						<td width=300 height=80 align=center><html:errors/></td>
    					</tr>
    				</table>
    				<br>
    				<br>
    				<table border=1 cellspacing=0 cellpadding=20>
    					<tr>
    						<td height=20 align=center><font color="navy" size="2">Ce site est optimisé pour une utilisation en 1024*768 avec les navigateurs Mozilla 1.7, FireFox, Netscape 7.0  et Internet Explorer 6.0</font></td>
    					</tr>
    				</table>
    			</html:form>
    		</center>
    	</body>
    </html>
    le struts-config:
    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
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
     
    <form-beans>
    	<form-bean name="authentificationbean" type="beans.AuthentificationBean"/>
    </form-beans>
     
    <action-mappings>
    	<action
    	path="/formulaire_authentification"
    	parameter="/vues/formulaire.authentification.jsp"
    	type="org.apache.struts.actions.ForwardAction"/>
     
    	<action
    	path="/authentification"
    	name="authentificationbean"
    	validate="true"
    	input="/vues/formulaire.authentification.jsp" 
    	scope="session"
    	type="actions.AuthentificationAction">
    		<forward name="reponse_hotesse" path="/vues/accueil.hotesse.jsp"/>
    		<forward name="reponse_administrateur" path="/vues/accueil.administrateur.jsp"/>
    		<forward name="reponse_chef_service" path="/vues/accueil.chef.service.jsp"/>
    		<forward name="reponse_demandeur" path="/vues/accueil.demandeur.jsp"/>
    		<forward name="erreurlogin" path="/vues/formulaire.authentification.jsp"/>
    	</action>
     
    </action-mappings>
     
    <message-resources parameter="ressources"/>
     
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    	<set-property value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" property="pathnames"/>
    </plug-in>
     
    </struts-config>
    validation.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
     
    <?xml version="1.0" encoding="ISO-8859-1" ?>
     
    <!DOCTYPE form-validation PUBLIC
              "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
              "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
     
    <form-validation>
        <formset>
            <!-- Validation pour le formulaire d'authentification -->
            <form name="authentificationbean">
                <field
    				property="login"
                    depends="required">
                        <arg0 key="personne.authentification.login"/>
                </field>
                <field
                    property="password"
                    depends="required">
                        <arg0 key="personne.authentification.password"/>
                </field>
            </form>
        </formset>
    </form-validation>
    ressource.properties :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    errors.header=<ul>
    errors.footer=</ul>
    errors.required=<font color="red"><li>{0} manquant</li></font>
    personne.authentification.login=Nom d'utilisateur
    personne.authentification.password=Mot de passe
    et le bean

    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
    25
    26
    27
    28
    29
     
    package beans;
     
    import org.apache.struts.validator.ValidatorForm;
     
    public class AuthentificationBean extends ValidatorForm
    {
    	private String login = null;
    	private String password = null;
     
    	public String getLogin() 
    	{
    		return this.login;
    	}
    	public void setLogin(String login) 
    	{
    		this.login = login;
    	}
     
    	public String getPassword() 
    	{
    		return this.password;
    	}
     
    	public void setPassword(String password)
    	{
    		this.password = password;
    	}
    }
    A savoir qu on peut meme se passer du bean avec un dynaActionForm...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 19/09/2007, 17h11
  2. [ Struts ][ Validator ]problème d'affichage
    Par sebus dans le forum Struts 1
    Réponses: 13
    Dernier message: 17/05/2006, 16h32
  3. [EasyPHP] [Serveur] [EasyPHP/Wamp5]Non affichage des erreurs
    Par leodi dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 27/03/2006, 20h29
  4. [Struts-validator] Probleme de 0
    Par sylvain_neus dans le forum Struts 1
    Réponses: 5
    Dernier message: 14/10/2004, 12h37
  5. [Eclipse 3.0]Affichage des erreurs
    Par alfsalim dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 12/07/2004, 17h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo