salut, c'est encore moi !
J'ai un comportement un peu etonnant avec une classe action du type LookupDispatch.
Alors, je m'explique.
J'ai une classe action avec 3 redirections:
Un fichier de configuration qui mappe tout ca:
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 /******************************************************************************* * Copyright (c) 2005 Eteration A.S. and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: Eteration A.S. - initial API and implementation ******************************************************************************/ package myStruts.action; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import org.apache.struts.actions.LookupDispatchAction; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class AnimalAction extends LookupDispatchAction { public ActionForward pageAnimal(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // System.out.println("on passe dans la classe action"); String target = "pageAnimal"; return mapping.findForward(target); } public ActionForward pageProprietaire(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String target = "pageProprietaire"; return mapping.findForward(target); } /* public ActionForward pageAdresse(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String target = "affiche"; return mapping.findForward(target); } */ protected Map getKeyMethodMap() { HashMap<String, String> mapAnimal = new HashMap<String, String>(); mapAnimal.put("page.animal", "pageAnimal"); mapAnimal.put("page.proprietaire", "pageProprietaire"); //mapAnimal.put("page.adresse", "pageAdresse"); return mapAnimal; } }
Et ma page JSP, 'animal.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 <?xml version="1.0" encoding="UTF-8"?> <struts-config> <form-beans> <form-bean name="animalForm" type="myStruts.form.AnimalForm" /> </form-beans> <action-mappings> <action type="myStruts.action.AnimalAction" input="/pages/animal.jsp" name="animalForm" attribute="animal" path="/GestionAnimal" parameter="action" validate="true" > <forward name="pageAnimal" path="/pages/proprietaire.jsp" /> <forward name="pageProprietaire" path="/pages/adresse.jsp" /> <forward name="affiche" path="/pages/affiche.jsp" /> </action> </action-mappings> <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/> <message-resources parameter="MessageResources"/> <message-resources key="mesMessages" parameter="Struts.resources.messages"/> <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> <set-property property="moduleAware" value="true"/> </plug-in> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> </struts-config>
voilà pour le code, maintenant le comportement.
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 <%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <html:html> <head> <title>Informations relatives à l animal</title> </head> <body> <html:errors /> <html:form action="/GestionAnimal.do"> <bean:message key="animal.nom" bundle="mesMessages" /> <html:text property="nom"/> <html:errors property="nom" header="" footer="" prefix="" suffix="" /><br> <bean:message key="animal.dateNaiss" bundle="mesMessages" /> <html:text property="dateNaiss" /> <html:errors property="dateNaiss" header="" footer="" prefix="" suffix="" /><br> <bean:message key="animal.type" bundle="mesMessages" /> <html:text property="type" /> <html:errors property="type" header="" footer="" prefix="" suffix="" /><br> <html:submit property="action"> <bean:message key="page.animal" bundle="mesMessages" /> </html:submit> <html:hidden property="page" value="0" /> </html:form> </body> </html:html>
Lorsque je valide la page 'animal.jsp', apres avoir rempli tous les champs pour que le validator autorise la validation, j'appelle donc une redirection avec la classe qui hérite de LookupDispatch.
Je m'attend a ce que la redirection se fasse vers la page 'proprietaire.jsp' (vous aussi peut etre ?). Et bien la redirection passe directement a la page 'adresse.jsp'.
Si je met l'action 'pageProprietaire' ainsi que la ligne qui la rajoute dans la HashMap de la classe d'actionen commentaire, la redirection se fait bien vers la page 'proprietaire.jsp' comme c'est attendu.
Pour un supplément d'info je rajoute le code de la page 'proprietaire.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Proprietaire de l'animal</title> </head> <body> <html:errors /> <html:form action="/GestionAnimal.do"> <nested:root name="animal"> <bean:message key="animal.nom" bundle="mesMessages" /> <bean:write name="animal" property="nom" /><p> <nested:nest property="identite" > <bean:message key="identite.nom" bundle="mesMessages" /> <nested:text property="nom" /> <html:errors property="identite.nom" header="errors.entete" footer="errors.pied" prefix="" suffix="" /><br> <bean:message key="identite.prenom" bundle="mesMessages" /> <nested:text property="prenom" ></nested:text> <html:errors property="identite.prenom" header="errors.entete" footer="errors.pied" prefix="" suffix="" /><br> <bean:message key="identite.email" bundle="mesMessages" /> <nested:text property="email" ></nested:text> <html:errors property="identite.email" /><br> </nested:nest> <nested:hidden property="page" value="1"></nested:hidden> </nested:root> <html:submit property="action"> <bean:message key="page.proprietaire" bundle="mesMessages" /> </html:submit> </html:form> </body> </html:html>
Partager