Bonjour,
J'ai une dataTable qui affiche la liste des sociétés en base de données.
J'ai un commandButton qui affiche un dialog pour insérer une nouvelle société en base de données et ensuite réafficher la dataTable.
Tout fonctionne très bien, sauf que si je clique une 2ème fois sur le bouton pour ajouter une autre société, les champs dans mon dialog contiennent encore les valeurs de la première société que j'ai ajouté.
Il doit y avoir un problème de rafraichissement mais n'étant pas encore très à l'aise dans le domaine, je suis un peu bloqué....
Qqun pourrait-il m'aider svp ?
De plus je me posais la question suivante :Voici mon fichier xhtml:Est-ce qu'il est possible et judicieux d'avoir un formulaire lui-même inclus dans un autre formulaire ?
Par exemple, si j'avais créé un autre formulaire pour intégrer le dialogue de création d'une société, Est-ce que ça aurait été bien ou au contraire à éviter ?
Et mon BackingBean du formulaire :
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
106
107
108
109
110
111
112
113
114
115 <?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:growl id="messages" life="2000" /> <p:dialog header="#{msg['ConfirmerLaSuppression']}" widgetVar="confDeleteDlg" resizable="false" id="studentDlg" showEffect="fade" hideEffect="fade" > <p:outputLabel value="#{msg['EtesVouSurDeVouloirSupprimerCetteSociete']}" /> <div align="center"> <h:panelGrid id="display" columns="2" cellpadding="10"> <p:commandButton id="deleteButton" action="#{gestionSocietes.supprimerSociete}" oncomplete="PF('confDeleteDlg').hide()" update=":formulaire:gestionSocietes:societes" value="#{msg['Oui']}" /> <p:commandButton id="cancelButton" onclick="PF('confDeleteDlg').hide()" value="#{msg['Non']}"/> </h:panelGrid> </div> </p:dialog> <p:contextMenu for=":formulaire:gestionSocietes:societes"> <p:menuitem value="Supprimer" onclick="PF('confDeleteDlg').show()" update="messages" /> </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" 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" required="true" requiredMessage="#{msg['AbregeEstObligatoire']}"> <f:validateLength minimum="2" /> <p:ajax update="msgAbrege" event="keyup" /> </p:inputText> <p:outputLabel /> <p:message for="abrege" id="msgAbrege" /> <h:outputLabel for="nom" value="#{msg['Nom']} (50) : " styleClass="mandatory" /> <p:inputText id="nom" value="#{gestionSocietes.nom}" required="true" size="50" maxlength="50" /> <p:outputLabel /> <p:message for="nom" display="icon" /> <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>
Merci d'avance pour votre aide
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 @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 SocieteService m_societeService; /** * Default Constructor */ public GestionSocietesBean() { } public SocietesDataTableModel getListSocietes() { listSocietes = new ArrayList<>(); listSocietes = m_societeService.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_societeService.deleteSociete(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_societeService.createSociete(societe); } }
Partager