Bonjour à tous,
Adepte de la programmation Java mais encore novice dans Struts, j'ai besoin de votre aide.
Je dois réaliser un petit carnet d'adresse, permettant le listage, l'ajout, la suppression et la modification de contacts.
Mon problème se situe dans le listage des contact ! Je mets ci dessous le code des quatres fichiers concernés, struts-config.xml ; mon ActionForm (ContactListForm), l'action qui me redirige vers ma page JSP (ToIndexAction) et ma page JSP ou je désire effectuer mon listage (index.jsp).
ContactListForm
-------------------------------------
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 public class ContactListForm extends ActionForm { private Collection contacts; public ContactListForm(){ } public Collection getContacts(){ return contacts; } public void setContacts(Collection c){ contacts = c; } }
struts-config.xml
------------------------
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 <struts-config> <form-beans> <form-bean name="contactForm" type="forms.ContactForm" /> <form-bean name="contactListForm" type="forms.ContactListForm"/> </form-beans> ..... <action-mappings> .... <action path="/toIndex" scope="request" validate="false" attribute="contactListForm" input="/pages/index.jsp" type="actions.ToIndexAction" > <forward name="success" path="/pages/index.jsp"></forward> </action> .... </action-mappings> </struts-config>
ToIndexAction.java
---------------------------
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 ToIndexAction extends Action { Statement stmt; public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ConnexionDB conn = new ConnexionDB(); ContactDB contact = new ContactDB(conn.getConnection()); ContactListForm liste = new ContactListForm(); ArrayList tmp = contact.listAgenda(); liste.setContacts(tmp); return mapping.findForward("success"); } }
et 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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %> <html> <body> <h1>Mon agenda</h1> <table> <tr> <td>id</td> <td>Nom</td> <td>Prénom</td> <td>Adresse</td> <td>Téléphone</td> <td>Mail</td> <td></td> </tr> <logic:empty name="contactListForm" property="contacts"> <tr> <td colspan="6">No contacts !!</td> </tr> </logic:empty> <logic:notEmpty name="contactListForm" property="contacts"> <logic:iterate name="contactListForm" property="contacts" id="contact"> <tr> <td><bean:write name="contact" property="id"/></td> <td><bean:write name="contact" property="name"/></td> <td><bean:write name="contact" property="firstanme"/></td> <td><bean:write name="contact" property="address"/></td> <td><bean:write name="contact" property="tel"/></td> <td><bean:write name="contact" property="mail"/></td> </tr> </logic:iterate> </logic:notEmpty> </table> <a href="/ContactBook/addContactForm.do">Add</a> </body> </html>
Lors de l'éxécution de la page http://localhost:8080/ContactBook/toIndex.do j'obtiens l'erreur suivante :
Cannot find bean: "contactListForm" in any scope
Je pense que l'erreur se situe dans le struts-config.xml mais à vrai je ne sais plus trop tellement j'ai essayé de truc....
J'espère que quelqu'un pourra m'aider,
Merci
Partager