Bonjour,
je suis débutant dans le developpement JEE5, voila, j'ai utilisé netbeans 6.1 et glassfish 3 aussi EJB3 avec JDK 1.6.
Mon serveur est bien démarrer aussi j'ai bien configurer ma base dans glassfish et connecter
c'est une application de gestion de commandes que j'ai pris sur internet pour m'entrainer et voici les différents codes :
persistence.xml
mes servelets :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="PriseCommandes-ejbPU" transaction-type="JTA"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <jta-data-source>jdbc/Commande</jta-data-source> <properties> <property name="toplink.ddl-generation" value="drop-and-create-tables"/> </properties> </persistence-unit> </persistence>
Article.java
Commande.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
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
59
60
61
62
63
64
65
66
67
68
69
70
71 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.magasin; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; /** * * @author sofiane */ @Entity public class Article implements Serializable { private static final long serialVersionUID = 1L; private Integer id; String description; public void add(Article article) { throw new UnsupportedOperationException("Not yet implemented"); } public void setDescription(String article) { throw new UnsupportedOperationException("Not yet implemented"); } public void setId(Integer id) { this.id = id; } @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="ID_ARTICLE") public Integer getId() { return id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Article)) { return false; } Article other = (Article) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "org.magasin.Article[id=" + id + "]"; } }
GestionCommandesBean.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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.magasin; import java.io.Serializable; import java.util.Collection; import java.util.Date; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Temporal; /** * * @author sofiane */ @Entity(name="COMMANDE_CLIENT") public class Commande implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String client; @Temporal(value = javax.persistence.TemporalType.DATE) private Date dateLivraison; @OneToMany(cascade = CascadeType.ALL) private Collection<Article> articles; public void setId(Long id) { this.id = id; } public Long getId() { return id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Commande)) { return false; } Commande other = (Commande) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "org.magasin.Commande[id=" + id + "]"; } public String getClient() { return client; } public void setClient(String client) { this.client = client; } public Date getDateLivraison() { return dateLivraison; } public void setDateLivraison(Date dateLivraison) { this.dateLivraison = dateLivraison; } public Collection<Article> getArticles() { return articles; } public void setArticles(Collection<Article> articles) { this.articles = articles; } }
GestionCommandesLocal.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.magasin; import java.util.Collection; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author sofiane */ @Stateless public class GestionCommandesBean implements GestionCommandesLocal { @PersistenceContext() EntityManager em; public void creerCommande(Commande commande) { em.persist(commande); } public Collection<Commande> getCommandes() { return em.createQuery("SELECT o from COMMANDE_CLIENT o").getResultList(); } public void businessMethod(String creerCommandes) { throw new UnsupportedOperationException("Not supported yet."); } // Add business logic below. (Right-click in editor and choose // "EJB Methods > Add Business Method" or "Web Service > Add Operation") }
faces-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
18
19
20
21
22
23 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.magasin; import java.util.Collection; import javax.ejb.Local; /** * * @author sofiane */ @Local public interface GestionCommandesLocal { void creerCommande(Commande commande); Collection<Commande> getCommandes(); void businessMethod(String creerCommandes); }
web.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
18
19
20
21
22
23
24
25 <?xml version='1.0' encoding='UTF-8'?> <!-- =========== FULL CONFIGURATION FILE ================================== --> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> <managed-bean> <managed-bean-name>PriseCommande</managed-bean-name> <managed-bean-class>org.jsfmagasin.PriseCommande</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <navigation-rule> <description> </description> <from-view-id>/welcomeJSF.jsp</from-view-id> <navigation-case> <from-outcome>commande_passee</from-outcome> <to-view-id>/listeCommandes.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>
listeCommandes.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 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>com.sun.faces.verifyObjects</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>com.sun.faces.validateXml</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
welcomeJSF.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 <%-- Document : listeCommandes Created on : 14 oct. 2009, 00:12:19 Author : sofiane --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <!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=UTF-8"> <title>JSP Page</title> </head> <body> <f:view> <h:form> <h1><h:outputText value="List"/></h1> <h:dataTable value="#{PriseCommande.listeCommandes}" var="item"> <h:column> <f:facet name="header"> <h:outputText value="Client"/> </f:facet> <h:outputText value=" #{item.client}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="DateLivraison"/> </f:facet> <h:outputText value="#{item.dateLivraison}"> <f:convertDateTime type="DATE" pattern="MM/dd/yyyy" /> </h:outputText> </h:column> </h:dataTable> </h:form> </f:view> </body> </html>
PriseCommande.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@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"> <%-- This file is an entry point for JavaServer Faces application. --%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <f:view> <h:form> <h:panelGrid columns="3" border="0"> <h:outputText>Client</h:outputText> <h:inputText id="client" value="#{PriseCommande.client}"/> <h:message for="client"/> <h:outputText>Date Livraison jj/mm/aaaa:</h:outputText> <h:inputText id="dateLivraison" value="#{PriseCommande.dateLivraison}"> <f:convertDateTime pattern="dd/MM/yyyy"/> </h:inputText> <h:message for="dateLivraison"/> <h:outputText>Article</h:outputText> <h:inputText id="article" value="#{PriseCommande.article}"/> <h:message for="article"/> </h:panelGrid> <h:commandButton id="submit" value="Save" action="#{PriseCommande.sauve}"/> </h:form> </f:view> </body> </html>
Donc après un RUN du projet tout va bien pour le moment, j'ai la pages d'accueil ou je vais saisir mes 3 champs et après validation voici l'erreur qui j'ai
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.jsfmagasin; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import javax.ejb.EJB; import org.magasin.Article; import org.magasin.Commande; import org.magasin.GestionCommandesLocal; /** * * @author sofiane */ public class PriseCommande { @EJB GestionCommandesLocal processusCommande; private String Client; private Date dateLivraison; private String article; public String sauve(){ Commande commande = new Commande(); commande.setClient(getClient()); commande.setDateLivraison(getDateLivraison()); Article article = new Article(); article.setDescription(getArticle()); Collection<Article> articles = new ArrayList(); articles.add(article); commande.setArticles(articles); processusCommande.creerCommande(commande); return "commande_passee"; } public Collection<PriseCommande> getListeCommandes(){ Collection <PriseCommande> commandes = new ArrayList(); for (Commande commande : processusCommande.getCommandes()){ PriseCommande priseCommande = new PriseCommande(); priseCommande.setClient(commande.getClient()); priseCommande.setDateLivraison(commande.getDateLivraison()); commandes.add(priseCommande); } return commandes; } /** Creates a new instance of PriseCommande */ public PriseCommande() { } public String getClient() { return Client; } public void setClient(String Client) { this.Client = Client; } public Date getDateLivraison() { return dateLivraison; } public void setDateLivraison(Date dateLivraison) { this.dateLivraison = dateLivraison; } public String getArticle() { return article; } public void setArticle(String article) { this.article = article; } }
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 État HTTP 500 - type Rapport d'exception Message DescriptionLe serveur a rencontré une erreur interne () qui l'a empêché de remplir cette requête. Exception javax.servlet.ServletException: #{PriseCommande.sauve}: java.lang.UnsupportedOperationException: Not yet implemented Cause racine javax.faces.FacesException: #{PriseCommande.sauve}: java.lang.UnsupportedOperationException: Not yet implemented Cause racine javax.faces.el.EvaluationException: java.lang.UnsupportedOperationException: Not yet implemented Cause racine java.lang.UnsupportedOperationException: Not yet implemented note Les suivis de pile complets de l'exception et de ses causes principales sont disponibles dans les journaux Sun Java System Application Server 9.1_02. Sun Java System Application Server 9.1_02
je vous remercie d'avance pour votre aides
Partager