Bonjour !
je voudrais faire une liste déroulante avec un événement onchange
lorsque je sélectionne un élément ,les champs text se charge en fonction de l'élément choisi
---> le code de mon struts-config
---> le code de ma classe action Initialisation :
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 <form-beans> <form-bean name="factureIBForm" type="com.eccgnet.chan.facturationIB.form.FactureIBForm"/> </form-beans> <action-mappings> <action path="/initNum" validate="false" scope="request" name="factureIBForm" type="com.facturationIB.Initialisation" > <forward path="/vues/facturation/agentIB/factureIB.jsp" name="initNum"/> </action> <action path="/factureIB" name="factureIBForm" validate="false" scope="request" parameter= "/vues/facturation/agentIB/factureIB.jsp" type="com.facturationIB.FacturationAction" input = "/vues/facturation/agentIB/factureIB.jsp"> <forward path="/reponse.do" name="factureIB"/> </action> </action-mappings>
---> le code de mon actionForm:
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 Connection con = null; FactureIBForm formulaire=(FactureIBForm) form; String pu=""; String prix_d=""; int idMedoc=0; List allMedic=new ArrayList(); if(formulaire.getPu()!=null && formulaire.getPu()!="") { pu=(String) formulaire.getPu(); } if(formulaire.getPrix_d()!=null && formulaire.getPrix_d()!="") { prix_d=(String) formulaire.getPrix_d(); } try { //ici je recupere la liste : operation ok Medicament med=new Medicament(); allMedic=med.ListeMed(con); allMedic=med.ListeMed(con); // ensuite je teste si le formulaire contient l'element selectionnné if( formulaire.getIdMedoc()!=0) { idMedoc =formulaire.getIdMedoc(); // ensuite je fais le traitement sur des champs text a remplir prix_d=String.valueOf(med.getMedicamentPrixDetail(con,idMedoc)); pu=String.valueOf(med.getMedicamentPrixU(con,idMedoc)); formulaire.setPu("pu"); formulaire.setPrix_d("prix_d"); } con.close(); } catch (Exception ex) { erreurs.add("ds",new ActionError("erreur.trm","")); this.saveErrors(request, erreurs); return mapping.findForward("afficherErreurs"); } //formulaire.setAllMedic(allMedic); request.setAttribute("allMedic",allMedic); return mapping.findForward("initNum");
---> et le code dans ma 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
54
55
56
57
58 public class FactureIBForm extends ActionForm { private List allMedic=new ArrayList(); private int idMedoc ; private String prix_d; private String pu; /** * @return Returns the allMedic. */ public List getAllMedic() { return allMedic; } /** * @param allMedic The allMedic to set. */ public void setAllMedic(List allMedic) { this.allMedic = allMedic; } /** * @return Returns the idMedoc. */ public int getIdMedoc() { return idMedoc; } /** * @param idMedoc The idMedoc to set. */ public void setIdMedoc(int idMedoc) { this.idMedoc = idMedoc; } /** * @return Returns the prix_d. */ public String getPrix_d() { return prix_d; } /** * @param prix_d The prix_d to set. */ public void setPrix_d(String prix_d) { this.prix_d = prix_d; } /** * @return Returns the pu. */ public String getPu() { return pu; } /** * @param pu The pu to set. */ public void setPu(String pu) { this.pu = pu; } }
Mon problème c'est que la liste j'arrive au moins a la récupérer mais j'ai l'impression que l'action ne s'exécute pas ou que l'élément sélectionné n'est pas récupérer
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 <script> var path = window.location.pathname.substring(0,window.location.pathname.lastIndexOf('/')+1); function filtreForm(theForm,url) { //var chemin = path+url; //theForm.action = chemin; theForm.action =url; theForm.submit(); } </script> <html:form action="/factureIB.do" method="post"> <html:select property="idMedoc" onchange="filtreForm(this.form,'/initNum.do')" > <html:optionsCollection name="allMedic" value="idMedoc" label="libelleMedoc"/> </html:select> <html:text property="pu" /> <html:text property="prix_d" /> <html:submit > <bean:message key="submit.factureIB.value"/> </html:submit> </html:form>
Quelqu'un a t'il une idée car le problème a mon niveau c'est que je n'arrive pas a voir ou se trouve l'erreur , peut être que je mélange tout
Merci d'avance!
Partager