Bonjour à tous


Voila je suis entrain de d'apprendre à me servir de Struts et de son plugin Validator. J'ai pour cela créer un formulaire tout bete avec 3 champs dont 1 qui nécessite la présence d'un entier.

Voici mon 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
 
<struts-config>
	<form-beans>
		<form-bean name="form1" type="com.projet.forms.PersonneForm" />
	</form-beans>
 
	<action-mappings>
 
		<action path="/FirstPage" scope="request" type="com.projet.actions.FirstPageAction">
			<forward name="gofirstpage" path="main"></forward>
		</action>
 
		<action path="/AddPersonne" scope="request"
		type="com.projet.actions.AddPersonneSubmitAction"
			name="form1" attribute="PerForm" input="main" parameter="main">
 
			<forward name="return" path="main"></forward>
		</action>
 
	</action-mappings>
 
	<message-resources parameter="com.projet.resources.messages" />
 
	<plug-in className="org.apache.struts.tiles.TilesPlugin">
		<set-property property="moduleAware" value="true" />
		<set-property property="definitions-config" 
			value="/WEB-INF/tiles-defs.xml" />
		<set-property property="definitions-parser-validate" value="true" />
 
	</plug-in>
 
	<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
		<set-property property="pathnames"
			value="/WEB-INF/validation.xml,/WEB-INF/validator-rules.xml" />
	</plug-in>
 
</struts-config>

Mon formulaire jsp :
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
 
<html>
<head>
<title><bean:message key="form" /></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<p><font size="4"><bean:message key="form" /></font></p>
 
<html:form action="/AddPersonne">
 
<table>
<tr>
	<td><bean:message key="last_name" /></td>
	<td><html:text property="per.lastNane" /></td>
	<td><html:errors property="per.lastNane" /></td>
</tr>
<tr>
	<td><bean:message key="first_name" /></td>
	<td><html:text property="per.firstName" /></td>
	<td><html:errors property="per.description" /></td>
</tr>
<tr>
	<td><bean:message key="age" /></td>
	<td><html:text property="per.age" /></td>
	<td><html:errors property="per.age" /></td>
</tr>
 
</table>
<html:submit><bean:message key="add" /></html:submit>
 
</html:form>
<br>
</body>
</html>

Mon fichier validation.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
<form-validation>
	<formset>
		<form name="PerForm">
			<field property="per.age" depends="integer">
				<arg key="errors.age" />
			</field>
		</form>
	</formset>
</form-validation>
Pour finir ma classe Form :

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
 
public class PersonneForm extends ValidatorForm {
 
	private static final long serialVersionUID = 1L;
 
	Personne per;
 
	public PersonneForm() {
		per = new Personne();
	}
 
	public Personne getPer() {
		return per;
	}
 
	public void setPer(Personne per) {
		this.per = per;
	}
}
Le validation-rules est celui par défaut et mes fichiers messages sont au bon endroit et contiennent une entrée :
errors.age = Entrez un entier --> pour le francais
errors.age = Not a number --> pour l'anglais

Tout à l'air ok pournant aucun message ne s'affiche lorsque je rentre des caracteres dans le champ age.

Si qqun à une idée elle serait la bienvenue car là je ne voit pas du tout ce qui cloche...

Merci d'avance
Bonne journée