I'm having a bit of an issue when trying to update an entity. I have a data table that contains a list of employees, and I'm trying to implement a method to update one employee. To do so I used a commandButton that opens a dialog box that's supposed to contain the informations of whichever employee we want to update. Unfortunately, the dialog box is showing empty fields.
Here is the code of my .xhtml:
<h:form>
<h:dataTable value="#{formateurController.findAll()}" var="item" border="1" styleClass="table table-hover" >
<h:column >
<f:facet name="header">
<h:outputText value="Nom"/>
</f:facet>
<h:outputText value="#{item.nom}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Action"/>
</f:facet>
<p:commandButton value="Modifier" onclick="PF('sample2').show();" action="#{formateurController.update(item)}" />
<p:dialog header="Modifier Formateur" widgetVar="sample2" >
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nom:" for="nom" />
<h:inputText id="nom" value="#{formateurController.formateur.nom}" title="Nom" required="true" requiredMessage="The Nom field is required."/>
</h:panelGrid>
<h:commandButton value = "modifier" action="#{formateurController.update()}"/>
</h:form>
</p:dialog>
</h:dataTable>
</h:form>
And my managed Bean code:
@SessionScoped
public class FormateurController implements Serializable {
public String update() {
//name updated
this.formateurFacade.edit(formateur);
this.formateur = new Formateur();
return "index";
}
public void update(Formateur formateur) {
this.formateur = formateur;
}
}