salut tout le monde, je m'adresse a votre sagesse et votre expérience.
j'ai un problème de struts, sur un formulaire, il y a des champs à remplir.
Pour ces champs, je fais une série de tests, et j'affiche les messages a côté en cas de non vérification des tests.
le problème est qu'il y a deux champs {compte et nom_admin} qui ne se vérifie pas, et d'autres champs qui font n'importe quoi.
Aussi, les messages d'erreurs pour les autres champs s'affichent dès le début sans que j'écris quoi que ce soit.

voici le ActionForm
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
public class AjouterAdminForm extends org.apache.struts.action.ActionForm {
 
   private String nom_admin;
   private String compte;
   private String add_mail;
   private String mot_de_passe;
   private String mot_de_passe_2;
 
 
   private String nom_admin_error;
   private String compte_error;
   private String add_mail_error;
   private String mot_de_passe_error;
   private String mot_de_passe_error2;
 
    public String getAdd_mail() {
        return add_mail;
    }
 
    public void setAdd_mail(String add_mail) {
        this.add_mail = add_mail;
    }
 
    public String getAdd_mail_error() {
        return add_mail_error;
    }
 
    public void setAdd_mail_error() {
        this.add_mail_error ="<span style='color:red'>Adresse mail non valide...</span>";
    }
 
    public String getCompte() {
        return compte;
    }
 
    public void setCompte(String compte) {
        this.compte = compte;
    }
 
    public String getCompte_error() {
        return compte_error;
    }
 
    public void setCompte_error() {
        this.compte_error = "<span style='color:red'>Le compte est vide...!</span>";
    }
 
    public void setCompte_error_2() {
        this.compte_error = "<span style='color:red'>Le compte est deja existant...!</span>";
    }
    public String getMot_de_passe() {
        return mot_de_passe;
    }
 
    public void setMot_de_passe(String mot_de_passe) {
        this.mot_de_passe = mot_de_passe;
    }
 
    public String getMot_de_passe_2() {
        return mot_de_passe_2;
    }
 
    public void setMot_de_passe_2(String mot_de_passe_2) {
        this.mot_de_passe_2 = mot_de_passe_2;
    }
 
    public String getMot_de_passe_error() {
        return mot_de_passe_error;
    }
 
    public void setMot_de_passe_error() {
        this.mot_de_passe_error = "Mot de passe trop court...";
    }
 
    public String getMot_de_passe_error2() {
        return mot_de_passe_error2;
    }
 
    public void setMot_de_passe_error2() {
        this.mot_de_passe_error2 = "<span style='color:red'>Mot de passe non identique...</span>";
    }
 
    public String getNom_admin() {
        return nom_admin;
    }
 
    public void setNom_admin(String nom_admin) {
        this.nom_admin = nom_admin;
    }
 
    public String getNom_admin_error() {
        return nom_admin_error;
    }
 
    public void setNom_admin_error() {
        this.nom_admin_error = "<span style='color:red'>Le Nom est vide...!</span>";
    }
 
   public AjouterAdminForm() {
       super();
       // TODO Auto-generated constructor stub
   }
 
   public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
       ActionErrors errors = new ActionErrors();
 
       return errors;
   }
}
et le Action

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AjouterAdminForm formbean = (AjouterAdminForm) form;
        ListeAdmin l = new ListeAdmin();
 
        boolean stat = true;
 
        if (formbean.getCompte() == null) {
 
            formbean.setCompte_error();
            stat = false;
        }
        else
        {
            while(l.résultat.next())
            {
                if (formbean.getCompte().equalsIgnoreCase(l.compte()))
                {
                    formbean.setCompte_error_2();
                    stat=false;
                }
            }
        }
        if (formbean.getNom_admin() == null) {
            formbean.setNom_admin_error();
            stat = false;
        }
        if (formbean.getMot_de_passe().length() < 4) {
            formbean.setMot_de_passe_error();
            stat = false;
        }
        if (!formbean.getMot_de_passe().equals(formbean.getMot_de_passe_2())) {
            formbean.setMot_de_passe_error2();
            stat = false;
        }
        if (!testEmail(formbean.getAdd_mail()))
        {   formbean.setAdd_mail_error();
            stat=false;
        }
        if (stat) {
            String req="INSERT INTO admin (nom_admin,compte,mot_de_passe,mail) VALUES (";
            req=req+"'"+formbean.getNom_admin()+"',";
            req=req+"'"+formbean.getCompte()+"',";
            req=req+"'"+formbean.getMot_de_passe()+"',";
            req=req+"'"+formbean.getAdd_mail()+"');";
            ConnexionBD con=new ConnexionBD();
            con.miseAJour(req);
            return mapping.findForward(SUCCESS);
        } else {
            return mapping.findForward(FAILLURE);
        }
    }
 
    public boolean testEmail(String email) {
        email = email.toLowerCase();
        String charOk = "abcdefghijklmnopqrstuvwxyz0123456789_@.";
        boolean test = false;
        if (email.length() < 8) {
            return false;
        }// Si l'email fait moins de 8 caractéres
 
        if (email.indexOf('@') < 0) {
            return false;
        }// Si l'email ne contient pas d'@'
 
        if (email.indexOf('.') < 0) {
            return false;
        }// Si l'email ne contient pas de '.'
 
        if (((email.indexOf('.', (((email.indexOf('@')) + 1))))) == (email.indexOf('@') + 1)) {
            return false;
        }// Si l'email as un '.' apres l'@
 
        if (((email.indexOf('.', (((email.indexOf('@')) - 1))))) == (email.indexOf('@') - 1)) {
            return false;
        }// Si l'email as un '.' avant l'@
 
        if ((email.indexOf('.')) == 0) {
            return false;
        }// Si l'email as un '.' au debut
 
        if ((email.charAt((email.length() - 1)) == '.')) {
            return false;
        }// Si l'email a un '.' a la fin
 
        if ((email.indexOf('@')) == 0) {
            return false;
        }// Si l'email as un '@' au debut
 
        if ((email.charAt((email.length() - 1)) == '@')) {
            return false;
        }// Si l'email a un '@' a la fin
        // Si l'email n'a pas de '.' un peu apres le '@'
 
        boolean tmp = false;
        for (int i = 1; i < (email.length() - (email.indexOf('@'))); i++) {
            if (email.charAt((email.indexOf('@')) + i) == '.') {
                tmp = true;
                i = (email.length());
            }
        }
        if (tmp == false) {
            return false;
        }
        // Si l'email a plusieurs '@'
        for (int i = 0; i < email.length(); i++) {
            if (email.charAt(i) == '@') {
                for (int j = i + 1; j < email.length(); j++) {
                    if (email.charAt(j) == '@') {
                        return false;
                    }
                }
            }
        }
        // Si l'email a 2 '.' d'affilé
        for (int i = 0; i < (email.length() - 1); i++) {
            if ((email.charAt(i) == '.') && (email.charAt(i + 1) == '.')) {
                return false;
            }
        }
        // Si l'email contient un caractére interdis
        for (int i = 0; i < email.length(); i++) {
            for (int j = 0; j < charOk.length(); j++) {
                if ((email.charAt(i)) == (charOk.charAt(j))) {
                    test = true;
                    j = (charOk.length());
                } else {
                    test = false;
                }
            }
            if (test == false) {
                return test;
            }
        }
        return test;
    }
}
merci d'avance