0

版本:PrimeFaces 3.5、JPA 2.1、GlassFish 4.0、Java EE 7、JSF 2.0。

对话框正常打开并显示版本数据,但此对话框中的“更新”按钮不起作用。按钮代码如下:

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

完整的对话代码:

<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>

更新 dataTable 中的 commandButton:

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

托管 bean 中的方法 save():

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;
}

存储库中的方法 edit() :

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

如果没有 ajax="false",更新实体的按钮将不起作用。

4

2 回答 2

0

你的数据表在哪里?

只需重新创建/重建您的数据表值。

在您的 managedbean/backing bean 中,在 CRUD 操作执行后添加此方法

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

在您的会话 bean 中

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

更新你的数据表 (update=":tblFuncionarios")

有关参考,请参阅 Primefaces 数据表重置和重新加载数据中的此问题

于 2013-12-01T14:44:26.413 回答
0

由于 Erick R. Ribeiro 在 PrimeFaces Facebook 组中的提示,添加ActionEvent actionEventsave方法的参数,现在它可以工作了。

于 2013-12-04T12:28:32.647 回答