Bonjour,
Débutant en JEE et JSF, je réalise mes premiers beans.
Je suis sous eclipse helios, jboss 6 et jsf 2.0.
J'ai 2 projets sous eclipse :
- un projet JSF (qui contient mes xhtml et mon managed bean)
- un projet EJB/JPA (qui contient un ejb entité, un ejb stateless et son interface)
**** Mon projet EJB/JPA
Mon entity :
Mon stateless
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 package com.galhauban.patrimoine.batiment; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity @Table(name="BATIMENT") @SequenceGenerator(name = "seqbati", sequenceName = "SEQ_BATIMENT") public class BatimentEntity { private Integer bat_id; private String bat_name; public BatimentEntity() {} /** * @return the bat_id */ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqbati") public Integer getBat_id() { return bat_id; } /** * @param bat_id the bat_id to set */ public void setBat_id(Integer bat_id) { this.bat_id = bat_id; } /** * @return the bat_name */ public String getBat_name() { return bat_name; } /** * @param bat_name the bat_name to set */ public void setBat_name(String bat_name) { this.bat_name = bat_name; }; }
Mon interface
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 package com.galhauban.patrimoine.batiment; import javax.ejb.Local; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless(name="batimentBean") @Local(BatimentLocal.class) @PersistenceContext (unitName = "EJB-Patrimoine") public class BatimentBean implements BatimentLocal { private EntityManager em; private BatimentEntity batiment; public BatimentEntity getBatiment() { return batiment; } public void setBatiment(BatimentEntity batiment) { this.batiment = batiment; } public BatimentEntity searchBatiment(int nb){ //try { batiment = em.find(BatimentEntity.class, nb); em.persist(batiment); return batiment; /*} catch(Exception ex){ System.out.println("Exception stateless bean (BatimentBean) : "+ ex.getMessage()); return null; }*/ } }
Mon persitence.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 package com.galhauban.patrimoine.batiment; import javax.ejb.Local; @Local public interface BatimentLocal { BatimentEntity searchBatiment(int nb); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.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_2_0.xsd"> <persistence-unit name="EJB-Patrimoine"> <class>com.galhauban.patrimoine.batiment.BatimentEntity</class> </persistence-unit> </persistence>
**** Mon projet JSF
Mon managedbean
Mon formulaire xhtml
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 package com.galhauban.patrimoine.batiment; import java.io.Serializable; import javax.ejb.EJB; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="batimentController") @SessionScoped public class BatimentController implements Serializable { private static final long serialVersionUID = 1L; private int identifiant; private BatimentLocal building; private BatimentEntity batiment; public BatimentController(){}; public BatimentLocal getBuilding() { return building; } public void setBuilding(BatimentLocal building) { this.building = building; } public BatimentEntity getBatiment() { return batiment; } public void setBatiment(BatimentEntity batiment) { this.batiment = batiment; } public String doSearch() { batiment = building.searchBatiment(identifiant); return "building.found"; } public int getIdentifiant() { return identifiant; } public void setIdentifiant(int identifiant) { this.identifiant = identifiant; } }
Mon xhtml qui doit afficher le résultat
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head></h:head> <body> <ui:composition template="/templates/modele.xhtml"> <ui:define name="entete">REFERENTIEL BATIMENT</ui:define> <ui:define name="corps"> <h:form> <h:outputText value="ceci est un test" /> <h:inputText value="#{batimentController.identifiant}" /> <h:commandButton action="#{batimentController.doSearch}" value="Search" style=" width : 104px;"/> </h:form> </ui:define> </ui:composition> </body> </html>
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head></h:head> <body> <ui:composition template="/templates/modele.xhtml"> <ui:define name="entete">BATIMENT detail</ui:define> <ui:define name="corps"> <rich:panel style="border:0;width:60%;text-align:center"> <h:outputText value="#{batimentController.batiment.bat_name}" /> </rich:panel> </ui:define> </ui:composition> </body> </html>
Mon faces-config
Mon 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
26
27
28
29
30
31
32 <?xml version="1.0" encoding="UTF-8"?> <faces-config 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_2_0.xsd" version="2.0"> <navigation-rule> <from-view-id>/pages/inputname.xhtml</from-view-id> <navigation-case> <from-outcome>greeting</from-outcome> <to-view-id>/pages/greeting.xhtml</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/pages/test.xhtml</from-view-id> <navigation-case> <from-outcome>building.found</from-outcome> <to-view-id>/pages/batiment.xhtml</to-view-id> </navigation-case> </navigation-rule> <application> <resource-bundle> <base-name>resources</base-name> <var>msgs</var> </resource-bundle> </application> </faces-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
17
18
19
20
21
22
23 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>JSF-Patrimoine</display-name> <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>*.jsf</url-pattern> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>Le but du jeu est donc de fournir un identifiant via le formulaire pour obtenir le nom d'un batiment.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=jnp://127.0.0.1:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Le problème c'est que lorsque je déploie sous jboss via eclipse j'ai ce message d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 14:41:26,648 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/JSF-Patrimoine]] Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.web.jsf.integration.config.JBossMojarra20ConfigureListener: java.lang.NoClassDefFoundError: Lcom/galhauban/patrimoine/batiment/BatimentLocal;
Je suis un peu paumé et je ne sais pas pourquoi il attend la classe :
"Lcom/galhauban/patrimoine/batiment/BatimentLocal" alors que c'est
"com/galhauban/patrimoine/batiment/BatimentLocal" il n'y a pas de L devant?
Merci d'avance pour vos réponses
Couse1
Partager