Bonjour, j'aimerai submit mon formulaire en xhtml, mais je ne sais pas comment m'y prendre :
mon ejbLocator
Code xhtml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <h:panelGrid columns="2"> <h:outputLabel value="Nom UE : " /> <h:inputText name="module.nom_module" /> <h:outputLabel value="Intitule UE : " /> <h:inputText name="module.intitule_module"/> <h:outputLabel value="Nombre d'heures de TDs : " /> <h:inputText name="module.nb_heures_td" /> <h:outputLabel value="Nombre d'heures de cours : " /> <h:inputText name="module.nb_heures_cours" /> <h:commandButton type="submit" value="#{ApplicationBean.lesModules}" /> </h:panelGrid>
l'ejb ModuleManager
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 package controleur; import java.util.Hashtable; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import modele.ModuleManagerRemote; public class EjbLocator { private static Context ctx; private static EjbLocator instance = new EjbLocator(); private EjbLocator() { } public static EjbLocator getLocator() { return instance; } private <T> T getEjb(Class<T> ejbClass, String beanName) { try { final Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); final Context context = new InitialContext(jndiProperties); final String appName = "ProjetContactEAR"; final String moduleName = "ProjetContactEJB"; return (T) context.lookup("java:global/" + appName + "/" + moduleName + "/" + beanName + "!" + ejbClass.getName()); } catch (NamingException e) { return null; } }
et enfin, Module :
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 package modele; import java.util.Collection; import java.util.Hashtable; import javax.ejb.LocalBean; import javax.ejb.Stateless; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @Stateless @LocalBean public class ModuleManager implements ModuleManagerRemote { @PersistenceContext EntityManager em; @Override public Module ajouter(Module module) { em.persist(module); return module; } public Collection<Module> listeModules() { return em.createQuery("SELECT m FROM Module m").getResultList(); } }
Merci
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 package modele; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class Module implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue (strategy=GenerationType.AUTO) private int id_module; private String nom_module; private String intitule_module; private int nb_heures_cours; private int nb_heures_td; public Module() { } public Module(int id_module, String nom_module, String intitule_module, int nb_heures_cours, int nb_heures_td) { super(); this.id_module = id_module; this.nom_module = nom_module; this.intitule_module = intitule_module; this.nb_heures_cours = nb_heures_cours; this.nb_heures_td = nb_heures_td; } public int getid_module() { return id_module; } public void setid_module(String nom_module) { this.nom_module = nom_module; } public String getnom_module() { return nom_module; } public void setnom_module(String nom_module) { this.nom_module = nom_module; } public String getintitule_module() { return intitule_module; } public void setintitule_module(String intitule_module) { this.intitule_module = intitule_module; } public int getnb_heures_cours() { return nb_heures_cours; } public void setnb_heures_cours(int nb_heures_cours) { this.nb_heures_cours = nb_heures_cours; } public int getnb_heures_td() { return nb_heures_td; } public void setnb_heures_td(int nb_heures_td) { this.nb_heures_td = nb_heures_td; } }
Partager