0

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;

      
    }
}
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Does this answer your question? [How to use in JSF page? Single form? Multiple forms? Nested forms?](https://stackoverflow.com/questions/7371903/how-to-use-hform-in-jsf-page-single-form-multiple-forms-nested-forms) – Jasper de Vries Sep 29 '21 at 15:34
  • HTML does not allow having nested forms. On the other hand, update the components in the dialog to refresh the value. – ivasanpag Oct 19 '21 at 13:28

0 Answers0