0

我有一个简单的模型,在我的数据表中获取一些结果后尝试更新数据表,我正在使用 EJB 在我的数据库中获取这个结果。

问题是,搜索后,我的 dataTable 不会更新,除非单击搜索按钮 2 次或在 fieldText 过滤器中输入内容并清除它。

我尝试将一些功能设置为“onclick and update”,但所有解决方案都不起作用。

一个重要的情况是:如果从我的 dataTble 中删除了 fieldText 过滤器,则 d​​ataTable 会完美更新而没有错误:)。

有人可以说另一种方式或方向来解决我的问题吗?

xhtml代码:

<h:form id="frmPesquisa">
    <p:panelGrid columns="3">
        <h:outputLabel value="Pesquisar" for="pesquisa" />
        <h:inputText id="pesquisa"
            value="#{cadastroClienteBean.valorPesquisa}" />
        <p:commandButton value="Pesquisar"
            action="#{cadastroClienteBean.pesquisar}" update="tableResult"
            onclick="PF('itemListases').clearFilters(); PF('itemListases').filter();"/>
    </p:panelGrid>
    <br />
    <br />
    <br />
    <p:dataTable rendered="#{cadastroClienteBean.listaVazia()}" paginator="true" rows="5" widgetVar="itemListases"
        emptyMessage="Não foram encontrados Itens"
        filteredValue="#{cadastroClienteBean.filtrados}" id="tableResult"
        value="#{cadastroClienteBean.clientes}" var="cliente" border="1"
        cellpadding="5">
        <p:column headerText="Código" filterBy="#{cliente.codigo}">
            <h:outputText value="#{cliente.codigo}" />
        </p:column>
        <p:column headerText="Nome">
            <h:outputText value="#{cliente.nome}" />
        </p:column>
        <p:column headerText="Idade">
            <h:outputText value="#{cliente.idade}" />
        </p:column>
        <p:column headerText="Sexo">
            <h:outputText value="#{cliente.sexo}" />
        </p:column>
        <p:column headerText="Profissão">
            <h:outputText value="#{cliente.profissao}" />
        </p:column>
    </p:dataTable>
</h:form>

豆子代码:

@Named
@SessionScoped
public class CadastroClienteBean implements Serializable {

    private static final long serialVersionUID = 1L;

    private Cliente cliente;
    private List<Cliente> clientes;
    private List<Cliente> filtrados;
    private String valorPesquisa;
    private String pesquisaAnterior;

    @EJB
    CadastroClienteEJB cadastroClienteEJB;

    public CadastroClienteBean() {
        System.out.println("===> Chamou o CONSTRUTOR");
        cliente = new Cliente();
        clientes = new ArrayList<Cliente>();
        filtrados = new ArrayList<Cliente>();
    }

    public void pesquisar() {
        if (!valorPesquisa.equals(pesquisaAnterior)) {
            filtrados = new ArrayList<Cliente>();
            if (this.valorPesquisa == null || this.valorPesquisa.equals("")) {
                pesquisaAnterior = new String(valorPesquisa);
                this.clientes = cadastroClienteEJB.buscarTodos();
            } else {
                pesquisaAnterior = new String(valorPesquisa);
                this.clientes = this.cadastroClienteEJB
                        .pesquisar(this.valorPesquisa);
            }
        }
    }
4

1 回答 1

0

非常感谢。它完美地工作。我删除了我的数据表的渲染并放置了一个 id 标签。在我的命令按钮中,我插入了一个更新标签,将我的数据表的标签 ID 放入之前创建的。

于 2017-12-21T14:49:12.903 回答