Bonjour,
Dans l'absolu, je souhaiterai que lorsque j'arrive sur ma page index, son "IndexAction" soit déclenché afin d'initialiser les valeurs de son "IndexForm" et de les afficher dans la page (je sais pas si j'suis clair).
Tout cela n'étant visblement pas possible directement, j'ai crée une page jsp redirectIndex qui contient cette redirection :
Le but de cette page et de déclencher l'IndexAction qui lui initialise IndexForm avec les valeurs que je souhaites et redirige vers le vrai index.jsp qui affiche ces valeurs (en théorie...).
Code : Sélectionner tout - Visualiser dans une fenêtre à part <logic:forward name="index"/>
voila mon fichier struts-config.xml :
et voila mon fichier IndexAction :
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 <?xml version="1.0" encoding="UTF-8"?> <!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="LoginForm" type="com.nesbla.fastornot.web.Form.LoginForm" /> <form-bean name="IndexForm" type="com.nesbla.fastornot.web.Form.IndexForm" /> <form-bean name="InscriptionForm" type="com.nesbla.fastornot.web.Form.InscriptionForm" /> <form-bean name="NotationForm" type="com.nesbla.fastornot.web.Form.NotationForm" /> </form-beans> <global-forwards> <forward name="Connected" path="/Connected.jsp" /> <forward name="InscriptionConfirm" path="/InscriptionConfirm.jsp" /> <forward name="index" path="/index.jsp" /> </global-forwards> <action-mappings> <action path="/login" name="LoginForm" type="com.nesbla.fastornot.web.Action.LoginAction" scope="request"> </action> <action path="/notation" name="NotationForm" type="com.nesbla.fastornot.web.Action.NotationAction" scope="request"> </action> <action path="/index" name="IndexForm" type="com.nesbla.fastornot.web.Action.IndexAction" scope="request"> </action> <action path="/inscription" name="InscriptionForm" type="com.nesbla.fastornot.web.Action.InscriptionAction" input="/Inscription.jsp" validate="true"> </action> </action-mappings> </struts-config>
ansi que mon IndexForm :
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 public class IndexAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm _form, HttpServletRequest request, HttpServletResponse response ) throws Exception { // Récupère les données du formulaire. IndexForm form = (IndexForm) _form; // Définit la photo aléatoire. PhotoDao photoDao = new PhotoDao(); form.setPhoto(photoDao.getRandom()); return mapping.findForward("index"); } }
et enfin mon fichier index.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 public class IndexForm extends ActionForm { private static final long serialVersionUID = -6546500330056182574L; private Photo _photo; private String _test="test"; public String getTest() { return _test; } public void setTest(String test) { _test = test; } public Photo getPhoto() { return _photo; } public void setPhoto(Photo photo) { _photo = photo; } }
Donc au final, ce que je ne comprend pas, c'est que lorsque je vais sur ma page redirectIndex.jsp il semble executer l'IndexAction et il effectue correctement la redirection vers ma page index.jsp. Cependant celle-ci déclenche une erreur disant qu'il ne trouve pas le bean "IndexForm"... Etrange puisque celui-ci est correctement définit dans mon fichier struts-config et que j'opère de la même manière pour les autres pages et que ça marche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part test = <bean:write name="IndexForm" property="test"/>
voila l'erreur (qui est causé par mon <bean:write/>) :
La question que je me pose c'est de savoir si lorsque je passe dans mon IndexAction ca initialise correctement mon IndexForm. Je débute sous Struts donc je m'y prends peut être mal pour arriver à mes fins.
Code : Sélectionner tout - Visualiser dans une fenêtre à part javax.servlet.ServletException: Cannot find bean: "IndexForm" in any scope
Je suis tout ouïe à vos recommandations et eventuelles solutions.
Merci
Partager