Je suis en train de faire une formulaire d'ajout client:
partie métier:
Code:
1
2
3
4
5
6
7
8 @PersistenceContext(unitName="partieEjb") EntityManager em; public Clients ajoutClients(Clients c) { em.persist(c); return c; }
Version imprimable
Je suis en train de faire une formulaire d'ajout client:
partie métier:
Code:
1
2
3
4
5
6
7
8 @PersistenceContext(unitName="partieEjb") EntityManager em; public Clients ajoutClients(Clients c) { em.persist(c); return c; }
managedbens:
Code:
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 package test; import javax.ejb.EJB; import presentation.Clients; import service.GestionClientsLocal; public class AccountContoller { @EJB private GestionClientsLocal customerbean; private Clients cl=new Clients(); private int id; private String nom; private String prenom; public String docreateClients(){ cl=customerbean.ajoutClients(cl); return "cl"; } public AccountContoller (){ } public GestionClientsLocal getCustomerbean() { return customerbean; } public void setCustomerbean(GestionClientsLocal customerbean) { this.customerbean = customerbean; } public Clients getCl() { return cl; } public void setCl(Clients cl) { this.cl = cl; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } }
Code:
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <f:view> <h:form> <h:messages></h:messages> <h:panelGrid columns="2" columnClasses="rightAlign,leftAlign"> <h:outputText value="Identifiant:"> </h:outputText> <h:inputText label="Identifiant" value="#{accountContoller.id}" required="true"> </h:inputText> <h:outputText value="Nom:"></h:outputText> <h:inputText label="Nom" value="#{accountContoller.nom}" required="true"> <f:validateLength minimum="2" maximum="30"></f:validateLength> </h:inputText> <h:outputText value="Prenom:"> </h:outputText> <h:inputText label="Prenom" value="#{accountContoller.prenom}"> <f:validateLength minimum="3" maximum="30"></f:validateLength> </h:inputText> <h:panelGroup></h:panelGroup> <h:commandButton value="Create Client" action="#{accountContoller.docreateClients}" type="submit"></h:commandButton> </h:panelGrid> </h:form> </f:view> </body> </html>
Quand je fait l'exécution la formualire est affiché mais quand je clic sur le bouton "ajout"il ya une message d'erreur quii est affiché:
description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
Code:
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 exception javax.servlet.ServletException: #{accountContoller.docreateClients}: java.lang.NullPointerException javax.faces.webapp.FacesServlet.service(FacesServlet.java:256) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) cause mère javax.faces.FacesException: #{accountContoller.docreateClients}: java.lang.NullPointerException com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107) javax.faces.component.UICommand.broadcast(UICommand.java:383) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117) javax.faces.webapp.FacesServlet.service(FacesServlet.java:244) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) cause mère javax.faces.el.EvaluationException: java.lang.NullPointerException javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91) com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91) javax.faces.component.UICommand.broadcast(UICommand.java:383) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117) javax.faces.webapp.FacesServlet.service(FacesServlet.java:244) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) cause mère java.lang.NullPointerException test.AccountContoller.docreateClients(AccountContoller.java:19) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:585) org.apache.el.parser.AstValue.invoke(AstValue.java:131) org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68) javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77) com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91) javax.faces.component.UICommand.broadcast(UICommand.java:383) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97) com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117) javax.faces.webapp.FacesServlet.service(FacesServlet.java:244) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
Merci beaucoup pour votre aide:ccool: