Bonjour,
J'ai une page qui contient une dataTable avec un bouton permettant d'ajouter une nouvelle entrée dans la table via un dialogue contenant 3 champs.
Le problème est que lorsque j'appuie sur le bouton "Ajouter" de mon dialogue, la méthode ajouterSociete() doit créer une nouvelle instance de ma classe Societe et remplir les champs avec les valeurs du MangaedBean.
le problème est que ces champs sont toujours null.
Je ne vois pas ce que j'aurais pu oublier de faire, avez-vous une idée ?
Merci d'avance pour votre aide.
Voici la page :
Et le managedbean
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 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition template="../../../secured/modele/template.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"> <ui:define name="contenu"> <h:form id="gestionSocietes"> <p:dialog header="Student Detail" widgetVar="confirmation" resizable="false" id="studentDlg" showEffect="fade" hideEffect="explode" modal="true" appendTo="@(body)"> <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;"> <p:commandButton id="deleteButton" action="#{gestionSocietes.supprimerSociete}" oncomplete="PF('confirmation').hide()" update=":formulaire:gestionSocietes:societes" value="Delete"/> <p:commandButton id="cancelButton" onclick="PF('confirmation').hide()" value="Cancel"/> </h:panelGrid> </p:dialog> <p:contextMenu for=":formulaire:gestionSocietes:societes"> <p:menuitem value="Supprimer" onclick="PF('confirmation').show()" /> </p:contextMenu> <h2> <h:outputText value="#{msg['GestionDesSocietes']}" /> </h2> <p:dataTable id="societes" value="#{gestionSocietes.listSocietes}" var="societe" widgetVar="UserTable" filteredValue="" emptyMessage="#{msg['AucuneSocieteAAfficher']}" selection="#{gestionSocietes.selectedSociete}" selectionMode="single" editable="false" editmode="row" rowKey="#{societe.id}" paginator="true" paginatorPosition="bottom" rows="10" style="margin-bottom:10px" paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15"> <f:facet name="header"> <p:outputPanel> <div align="left"> <p:commandButton onclick="PF('societeAjout').show()" id="ajoutUserBtn" icon="ui-icon-action-ajouter" title="#{msg['AjouterUneSociete']}" /> </div> </p:outputPanel> </f:facet> <p:column style="width:5%"> <f:facet name="header"> # </f:facet> #{societe.id} </p:column> <p:column style="width:20%"> <f:facet name="header"> #{msg['Abrege']} </f:facet> #{societe.abrege} </p:column> <p:column style="width:30%"> <f:facet name="header"> #{msg['Nom']} </f:facet> #{societe.nom} </p:column> <p:column style="width:45%"> <f:facet name="header"> #{msg['Description']} </f:facet> #{societe.description} </p:column> </p:dataTable> <p:dialog header="#{msg['NouvelleSociete']}" widgetVar="societeAjout" resizable="false" id="societeAjout" modal="true" appendTo="@(body)" focus="abrege" > <h:panelGrid id="ajoutDial" width="500" columns="2" style="margin:0 auto;"> <h:outputLabel for="abrege" value="#{msg['Abrege']} (10) : " styleClass="mandatory" /> <p:inputText id="abrege" value="#{gestionSocietes.abrege}" size="50" maxlength="10" /> <h:outputLabel for="nom" value="#{msg['Nom']} (50) : " styleClass="mandatory" /> <p:inputText id="nom" value="#{gestionSocietes.nom}" size="50" maxlength="50" /> <h:outputLabel for="description" value="#{msg['Description']} (2'000) : " /> <p:inputTextarea id="description" value="#{gestionSocietes.description}" rows="5" cols="50" counter="countDesc" maxlength="2000" counterTemplate="{0} #{msg['Restants']}" autoResize="false" styleClass="unresizable" /> <h:outputText /> <h:outputText id="countDesc" /> <p:commandButton action="#{gestionSocietes.ajouterSociete}" update=":formulaire:gestionSocietes" value="#{msg['Ajouter']}" icon="ui-icon-check" style="margin:15px" oncomplete="PF('societeAjout').hide()"/> <p:commandButton value="#{msg['Annuler']}" icon="ui-icon-check" style="margin:15px" oncomplete="PF('societeAjout').hide()"/> <!-- <p:message for="name" id="msg_name"/> --> </h:panelGrid> </p:dialog> </h:form> </ui:define> </ui:composition>
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 @ManagedBean(name = "gestionSocietes") @RequestScoped public class GestionSocietesBean { private List<Societe> listSocietes; private Societe selectedSociete; private String abrege; private String nom; private String description; @EJB private SocieteDaoImpl m_societeDao; /** * Default Constructor */ public GestionSocietesBean() { } public SocietesDataTableModel getListSocietes() { listSocietes = new ArrayList<>(); listSocietes = m_societeDao.getSocieteList(); return new SocietesDataTableModel(listSocietes); } public Societe getSelectedSociete() { return this.selectedSociete; } public void setSelectedSociete(Societe selectedSociete) { this.selectedSociete = selectedSociete; } public void modifierSociete() { // TODO } public void supprimerSociete() { m_societeDao.delete(getSelectedSociete()); } public String getAbrege() { return abrege; } public void setAbrege(String abrege) { this.abrege = abrege; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public void ajouterSociete() { Societe societe = new Societe(); societe.setAbrege(this.abrege); societe.setNom(this.nom); societe.setDescription(this.description); m_societeDao.create(societe); } }
Partager