【问题标题】:Datatable is not updated after actionListener在 actionListener 之后数据表没有更新
【发布时间】:2019-11-08 13:33:06
【问题描述】:

当我使用这个执行过滤操作时,我在更新我的数据表时遇到了一些问题:

<p:panel styleClass="card" header="Filtri">
                        <h:panelGrid columns="4" layout="grid"
                            styleClass="ui-panelgrid-blank form-group">
                            <h:panelGroup styleClass="md-inputfield">
                                <p:inputText id="orderMinFilter" label="N. bolla più basso"
                                    value="#{productionOrdersView.orderNumberStartFilter}">
                                </p:inputText>
                                <p:outputLabel for="orderMinFilter" value="N. bolla più basso" />
                            </h:panelGroup>
                            <h:panelGroup styleClass="md-inputfield">
                                <p:inputText id="orderMaxFilter" label="N. bolla più alto"
                                    value="#{productionOrdersView.orderNumberEndFilter}">

                                </p:inputText>
                                <p:outputLabel for="orderMaxFilter" value="N. bolla più alto" />
                            </h:panelGroup>
                            <p:commandButton value="Cancella filtri" icon="ui-icon-clear"
                                styleClass="red-btn flat"
                                actionListener="#{productionOrdersView.clearFilter()}"
                                style="width:auto;margin-bottom:10px; float:right;"
                                update="dtOrders" />
                            <p:commandButton value="Cerca" icon="ui-icon-search"
                                styleClass="primary-btn flat"
                                actionListener="#{productionOrdersView.filter()}"
                                update="dtOrders"
                                style="width:auto;margin-bottom:10px; float:right;" />
                        </h:panelGrid>
                    </p:panel>

这是我的数据表:

<p:dataTable id="dtOrders" var="productionOrder"
                        value="#{productionOrdersView.orders}" selectionMode="single"
                        reflow="true" selection="#{productionOrdersView.selected}"
                        filteredValue="#{productionOrdersView.filtered}"
                        widgetVar="ordersTable" rowKey="#{productionOrder.pk}"
                        emptyMessage="Nessun elemento oppure la ricerca è ancora attiva..."
                        paginator="true" rows="20">

这就是方法:

public void filter() {
    if (orderNumberStartFilter != null && orderNumberEndFilter != null) {
        this.orders = productionOrderController.findFromToOrderNumber(Integer.valueOf(orderNumberStartFilter),
                Integer.valueOf(orderNumberEndFilter));
        this.filtered = orders;
    }
}

filter() 方法执行正确,并且 bean 中的列表正确(我搜索了 11 个元素并得到了它),但是 dataTable 已更新但没有使用这些值;为什么?我哪里错了?

【问题讨论】:

    标签: jsf primefaces javabeans


    【解决方案1】:

    你添加表单标签来更新commandButton的属性。

      <p:commandButton value="Cerca" icon="ui-icon-search"
                                styleClass="primary-btn flat"
                                actionListener="#{productionOrdersView.filter()}"
                                update=":formName:dtOrders"
                                style="width:auto;margin-bottom:10px; float:right;" />
    

    .

    【讨论】:

    • 它没有改变!事实上,如果我定价一次,然后一次正确更新表格!
    • 您检查过您的查询吗?如果它适用于一个字段(价格),它应该适用于其他字段。
    • jpql查询没问题!事实上,如果我在按钮上单击两次,表格就会正确更新,而没有一次。为什么?
    猜你喜欢
    • 2021-02-09
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 2018-10-16
    • 2012-07-18
    • 2017-03-09
    相关资源
    最近更新 更多