Bonjour : ce que je veux rélialiser c'est ca :
cad une liste de client qui s'affiche dans un tableau(contenu dans un formulaire), dans cette page il aurait 3 bouttons ajouter/modifier/supprimer pour la modification et la suppression je récupere l'id du client selectionné(boutton radio), j'ai trouvé plusieurs tutoriaux sur le forum j'ai essayé de faire la meme chose mais j'obtiens toujours des erreurs que je vais présenter ici :
pour ma liste de client j'ai definis :
ClientForm :
ClientAction :
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 package presentation.str; import java.util.List; import java.util.Vector; import org.apache.struts.action.ActionForm; import ma.corporate.planning.metier.Client; public class ClientsForm extends ActionForm{ private Client client=new Client(); private List clients=new Vector(); public Client getClient() { return client; } public void setClient(Client client) { this.client = client; } public List getClients() { return clients; } public void setClients(List clients) { this.clients = clients; } }
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 package presentation.str; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ma.corporate.planning.metier.GestClient; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class ClientsAction extends Action{ public ActionForward execute( ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ClientsForm cfs=(ClientsForm)form; GestClient gcs = new GestClient(); cfs.setClients(gcs.getAllClient()); return map.findForward("VueClients"); } }
Pour les autres pages :
j'ai défini :
CartForm :
CartAction :
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 package presentation.str; import javax.servlet.http.HttpServletRequest; import ma.corporate.planning.metier.GestClient; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class CartForm extends ActionForm { private String raisonSocial; private String adresse; private String tel; private String email; private String ville; private String pays; public String getRaisonSocial() { return raisonSocial; } public void setRaisonSocial(String raisonSocial) { this.raisonSocial = raisonSocial; } public String getAdresse() { return adresse; } public void setAdresse(String adresse) { this.adresse = adresse; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getVille() { return ville; } public void setVille(String ville) { this.ville = ville; } public String getPays() { return pays; } public void setPays(String pays) { this.pays = pays; } public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) { ActionErrors errors = new ActionErrors(); if ((raisonSocial == null) || (raisonSocial.length() < 1)) errors.add("raisonSocial", new ActionError("error.raisonSocial.vide")); if ((adresse == null) || (adresse.length() < 1)) errors.add("adresse", new ActionError("error.adresse.vide")); if ((tel == null) ){ errors.add("tel", new ActionError("error.tel.vide")); } else { if (!tel.matches("^\\s*\\d+\\s*$") || (tel.length() < 9)) { errors.add("telinvalide", new ActionError("error.tel.invalide")); } } if ((email == null) || (email.length() < 1)){ errors.add("email", new ActionError("error.email.vide")); } else { if (!email.matches(".+@.+\\.[a-z]+")) { errors.add("emailinvalide", new ActionError("error.email.invalide")); } } if ((ville == null) || (ville.length() < 1)){ errors.add("ville", new ActionError("error.ville.vide")); }//(!ville.matches("[^0-9]*")) else { if (!ville.matches("[^0-9]*")) { errors.add("villeinvalide", new ActionError("error.ville.invalide")); } } if ((pays == null) || (pays.length() < 1)){ errors.add("pays", new ActionError("error.pays.vide")); } else { if (!pays.matches("[^0-9]*")) { errors.add("paysinvalide", new ActionError("error.pays.invalide")); } } return errors; } }
et voila mon 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 package presentation.str; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ma.corporate.planning.metier.GestClient; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.apache.struts.actions.LookupDispatchAction; public class CartAction extends LookupDispatchAction { public ActionForward add( ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { GestClient gc = new GestClient(); String soc = ((AjoutClientForm) form).getRaisonSocial(); String adr = ((AjoutClientForm) form).getAdresse(); String tel = ((AjoutClientForm) form).getTel(); String email = ((AjoutClientForm) form).getEmail(); String ville = ((AjoutClientForm) form).getVille(); String pays = ((AjoutClientForm) form).getPays(); ActionErrors errors = new ActionErrors(); ActionError newError = null; ActionMessages messages = new ActionMessages(); ActionMessage newMessage = null; Boolean t= gc.addClient(soc, adr, tel, email, ville, pays); if(t) { newMessage = new ActionMessage("message.ajout.client.succes"); messages.add("msgajoutclient", newMessage); this.saveMessages(request, messages); return map.findForward("success"); } else { newError = new ActionError("errors.doublons.Database"); errors.add(ActionErrors.GLOBAL_ERROR, newError); saveErrors(request, errors); return map.findForward("failure"); } } public ActionForward remove( ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { return map.findForward("listeclient"); } public ActionForward modify( ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { return map.findForward("listeclient"); } protected Map getKeyMethodMap() { Map map = new HashMap(); map.put("button.add", "add"); map.put("button.modify", "modify"); map.put("button.delete", "delete"); return map; } }
il ya quelque chose que m'échape parce qu'il me dit :
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 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="cfp" type="presentation.str.AjoutClientForm"/> <form-bean name="cfps" type="presentation.str.ClientsForm"/> <form-bean name="cartForm" type="presentation.str.CartForm"/> </form-beans> <global-forwards> <forward name="VueAjoutClient" path="/vues/AjouterClient.jsp"/> <forward name="VueClients" path="/vues/Clients.jsp"/> </global-forwards> <action-mappings> <action path="/listeclient" input="/vues/Clients.jsp" name="cfps" type="presentation.str.ClientsAction" scope="request" /> <action path="/ajoutclient" input="/vues/AjouterClient.jsp" name="cfp" type="presentation.str.AjoutClientAction" scope="request" validate="true"> <forward name="success" path="/listeclient.do" redirect="false"/> <forward name="failure" path="/vues/AjouterClient.jsp"/> </action> <action path="/modifclient" type="org.apache.struts.actions.ForwardAction" parameter="/vues/ModifierClient.jsp"> </action> <action path="/supclient" type="org.apache.struts.actions.ForwardAction" parameter="/vues/SupprimerClient.jsp"> </action> <action path="/cartManagement" type="app.management.CartAction" name="cartForm" scope="request" validate="true" parameter="monAction" /> </action-mappings> <message-resources parameter="ApplicationResources"/> </struts-config>message No input attribute for mapping path /cartManagement
Partager