0

Versions: PrimeFaces 3.5, JPA 2.1, GlassFish 4.0, Java EE 7, JSF 2.0.

Dialog normally opens and displays data for edition, but the "Update" button in this dialog is not working. Button code follows:

<p:commandButton actionListener="#{funcionarioMB.save}"
                                     value="Alterar"
                                     oncomplete="dlg.hide();"
                                     update=":tblFuncionarios"
                                     ajax="false" />

Full dialog code:

<p:dialog id="dlg"
              header="Editar funcionário"
              modal="true"
              widgetVar="editarDialog"
              closable="true"
              draggable="false"
              appendToBody="true"
              maximizable="false"
              minimizable="false"
              position="center"
              resizable="false"
              showEffect="slide">
        <p:outputPanel>
            <h:form id="formAlterar">
                <h:panelGrid id="infosFuncionario">

                    <!-- inputs -->

                    <p:commandButton actionListener="#{funcionarioMB.save}"
                                     value="Alterar"
                                     oncomplete="dlg.hide();"
                                     update=":tblFuncionarios"
                                     ajax="false" />
                </h:panelGrid>
            </h:form>
        </p:outputPanel>
    </p:dialog>

Update commandButton within the dataTable:

<h:form>
                <p:commandButton actionListener="#{funcionarioMB.prepareEdit(funcionario.id)}"
                                 value="alterar"
                                 oncomplete="editarDialog.show();"
                                 update=":formAlterar" />
            </h:form>

Method save() in the managed bean:

public void save() {
    Cargo cargo = this.cargoRepositorio.findById(this.cargoID);
    funcionario.setCargo(cargo);

    if (this.getFuncionario().getId() == null) {
        this.funcionarioRepositorio.add(this.getFuncionario());
    } else {
        this.funcionarioRepositorio.edit(this.getFuncionario());
    }
    this.funcionario = new Funcionario();
    this.funcionarios = null;
}

Method edit() in the repository:

public void edit(Funcionario funcionario) {
    this.manager.merge(funcionario);
}

And the button for updating the entity doesn't work without ajax="false".

Rasshu
  • 1,764
  • 6
  • 22
  • 53

2 Answers2

0

where is your datatable ?

just recreate/rebuild your datatable value.

in your managedbean/backing bean add this method after CRUD operation execute

public List<T> refreshDatatable(){
    list=yourEJBFacade().getList();
    return list
}

in your session bean

public List<T> getList(){
 Query q = entityManager.createQuery("select a from YourEntityClass a");
 return q.getResultList();
}

update your datatable (update=":tblFuncionarios")

for references see this question at Primefaces datatable Reset and Reload data

Community
  • 1
  • 1
0

Added ActionEvent actionEvent as save method's parameter and now it's working, thanks to Erick R. Ribeiro's hint in the PrimeFaces Facebook group.

Rasshu
  • 1,764
  • 6
  • 22
  • 53