Bonjour, je souhaite pré-remplir un formulaire et utiliser la méthode beanutils.copyproperties.J'utilise un bean, une classe métier, une action et un jsp. Mais j'ai un souci et je ne trouve pas le problème j'ai l'erreur:
voici mon struts-config.xml concernant les parties utiles:javax.servlet.ServletException: Cannot retrieve definition for form bean null on action /login
ma classe métier:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <for-beans> <form-bean name="frmDirection" type="com.struts.beans.FormBean"> </form-bean> </form-beans> <action-mappings> <action path="/initmodifydirection" name="frmDirection" scope="request" validate="false" type="com.struts.actions.InitFormAction"> <forward name="init" path="/vues/modifdirection.jsp"/> </action> </action-mappings>
mon bean:
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 public class Direction { private int id; private String firstname; private String lastname; public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname=firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname=lastname; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
mon 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
15
16
17
18
19
20
21
22
23
24
25
26 public class FormBean extends ActionForm { private int id; private String firstname; private String lastname; public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } }
et 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 public class InitFormAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException, NoSuchMethodException { // on a un formulaire valide, sinon on ne serait pas arrivé là FormBean formulaire=(FormBean)form; Direction d = new Direction(); d.setId(1); d.setFirstname("ben"); d.setLastname("ben"); try { BeanUtils.copyProperties(formulaire, d); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e.getCause()); } return mapping.findForward("init"); } }
donc je ne vois pas ce qui pose probleme, merci d'avance pour votre aide.
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 <html:form action="/login"> <table> <tr> <td>Nom : </td> <td><html:text property="lastname"/> </td> </tr> </table> <table> <tr> <td><html:submit value="Valider"/></td> <td><html:reset value="Rétablir"/></td> </tr> </table> </html:form>
Partager