Bonjour,
Je suis en train de suivre le tutoriel de Serge Tahé : ftp://ftp-developpez.com/tahe/fichie...ive/struts.pdf
Je bloque au chapitre IV Les formulaires dynamique
J'ai comme erreur :
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: No getter method for property: "name" of bean: "com.myapp.struts.PersonneDynaForm"
Biens sur que je n'ai pas de méthode getter car l'interet est de ne pas en avoir lorsque l'on utilise DynaActionForm en déclarant les noms des champs directement dans struts-config avec la balise form-property dans form-bean.
Enfin bon c'est ce que j'ai cru comprendre.
Pourquoi d'apres ai je cette erreur ?
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 <form-bean name="PersonneDynaForm" type="com.myapp.struts.PersonneDynaForm"> <form-property name="nom" type="java.lang.String" initial="" /> </form-bean> <action input="/erreurs.do" name="PersonneDynaForm" path="/main" scope="session" type="com.myapp.struts.FormulaireDynaAction" > <forward name="reponse" path="/reponse.do"/> </action>
La classe Action form : PersonneDynaForm.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
19
20
21
22
23
24
25
26 package com.myapp.struts; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class PersonneDynaForm extends org.apache.struts.action.DynaActionForm { public PersonneDynaForm() { super(); } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); String nom = (String) this.get("nom"); if (nom == null || nom.trim().equals("")) { errors.add("name", new ActionMessage("error.name.required")); // TODO: add 'error.name.required' key to your resources } return errors; } }
La classe Action :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public class FormulaireDynaAction extends org.apache.struts.action.Action { private final static String SUCCESS = "reponse"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PersonneDynaForm formulaire = (PersonneDynaForm) form; request.setAttribute("nom", "dynamique " + formulaire.get("nom")); return mapping.findForward(SUCCESS); } }
Partager