Bonjour
J'ai un validateur XML qui ne se declenche pas en struts2, si mon champ "password" est vide je passe quand meme ?
Ou est mon erreur ? Merci
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 La classe LoginActionc.java package tstValidator.strutsc; import com.opensymphony.xwork2.ActionSupport; public class LoginActionc extends ActionSupport { private String email; private String password; public String doSomething() { System.out.println("LoginActionc - doSomething DEBUT"); if (email != null && email.equals("admin@tstValidator.net")) { System.out.println("LoginActionc - doSomething retourSUCCES"); return SUCCESS; } else { System.out.println("LoginActionc - doSomething retour INPUT"); return INPUT; } } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } Dans le meme répertoire le XML LoginActionc-go-validation.xml <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> <validators> <field name="email"> <field-validator type="requiredstring"> <message>You must enter an e-mail address</message> </field-validator> <field-validator type="email"> <message>You must enter a valid e-mail address</message> </field-validator> </field> <field name="password"> <field-validator type="requiredstring"> <message>You must enter password</message> </field-validator> </field> </validators> La JSP <s:form action="go" method="post" namespace="/"> <s:textfield label="E-mail" name="email" /> <s:password label="Password" name="password" /> <s:submit method="doSomething" value="Appel action go méthode doSomething() de la class LoginActionc" /> </s:form> Le fichier de config struts.xml <action name="go" class="tstValidator.strutsc.LoginActionc" method="doSomething"> <result name="success" type="redirect">/LoginSuccess.jsp</result> <result name="input">/LoginFormc.jsp</result> </action>
Partager