Bonjour,
J'ai un problème avec Struts, j'ai du me rater quelque part car j'ai l'impression qu'il n'arrive pas à lire dans l'ActionForm...
J'ai un formulaire dans lequel un combobox doit etre rempli à partir d'un ArrayList. Donc ce que je fais, c'est que je lance l'Action directement, comme ca la méthode execute charge l'ArrayList, et forward vers la jsp.
Je précise que je n'ai aucun message d'erreur (ca m'aurait bien aidé) mais que l'affichage de la page comence puis s'arrête tout simplement.
Voici le code de l'Action de départ :
Voici le struts-config :
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 NouvelArretAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Avant d'afficher le formulaire de saisie, on doit récuperer les motifs type d'arret // Passe ici avant le premier affichage afin de récuperer la liste qui remplira le select NouvelArretForm c=(NouvelArretForm) form; // ArrayList l = new MotifArretMetier().getListePourSelect(); ArrayList l= new ArrayList(); l.add(new LabelValueBean("aaaa","aaaa")); l.add(new LabelValueBean("aaaa","aaaa")); c.setListeMotifs(l); request.setAttribute("var","jjj"); return mapping.findForward("afficheFormulaire"); }
voici l'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 <form-beans> <form-bean name="NouvelArretForm" type="com.myapp.struts.ActionForm.NouvelArretForm"/> <form-bean name="ListeArretsAgentForm" type="com.myapp.struts.ActionForm.ListeArretsAgentForm"/> <form-bean name="ChoixAgentForm" type="com.myapp.struts.ActionForm.ChoixAgentForm"/> <form-bean name="LoginActionForm" type="com.myapp.struts.ActionForm.LoginActionForm"/> </form-beans> <global-exceptions> </global-exceptions> <action-mappings> <action input="/login.jsp" name="LoginActionForm" path="/login" scope="session" type="com.myapp.struts.Action.LoginAction"> <forward name="success" path="site.index.page"/> </action> <action input="/choixAgentForm.jsp" name="ChoixAgentForm" path="/choixAgent" scope="session" type="com.myapp.struts.Action.ChoixAgentAction"> <forward name="afficheListeAgents" path="site.choixAgentForm.page"/> <forward name="afficheListeArrets" path="site.listeArretsAgent.page"/> <forward name="afficheListeConges" path="site.vueCongesAgent.page"/> </action> <action parameter="action" input="/Vues/listeArretsAgent.jsp" name="ListeArretsAgentForm" path="/traiterArrets" scope="session" type="com.myapp.struts.Action.ListeArretsAgentAction"> <forward name="nouvelArret" path="/nouvelArret.do"/> <forward name="supprimeArret" path="site.listeArretsAgent.page"/> <forward name="modifierArret" path="site.vueCongesAgent.page"/> </action> <action input="/Vues/listeArretsAgent.jsp" name="NouvelArretForm" path="/nouvelArret" scope="session" type="com.myapp.struts.Action.NouvelArretAction"> <forward name="afficheFormulaire" path="site.nouvelArret.page"/> </action>
et pour finir la vue :
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 public class NouvelArretForm extends org.apache.struts.action.ActionForm { private ArrayList listeMotifs=new ArrayList(); private String motif; public ArrayList getListeMotifs() { return listeMotifs; } public void setListeMotifs(ArrayList listeMotifs) { this.listeMotifs = listeMotifs; } /** * */ public NouvelArretForm() { super(); // TODO Auto-generated constructor stub } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); return errors; } public String getMotif() { return motif; } public void setMotif(String motif) { this.motif = motif; } }
Le pire c'est que la manip je l'ai déjà faite dans la même appli et que ca tourne bien !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <br /> <h3>Nouvel arrêt maladie pour l'agent <bean:write name="agent" property="nom"/> <bean:write name="agent" property="prenom"/></h3> <html:form action="nouvelArret"> Motif de l'arrêt : <logic:notEmpty property="listeMotifs"> <html:select property="motif"> <html:optionsCollection property="listeMotifs" value="value" label="label"/> </html:select> </logic:notEmpty> </html:form>
peut-être qu'à force de chercher il y a une erreur que je ne vois pas...
Partager