datatable没有更新

时间:2013-12-06 09:46:00

标签: jsf-2 primefaces

通过confirmDialog删除dataTable的所有元素后,数据表不会更新并保持填充

 <h:form id="form">  
<p:dataTable rowIndexVar="rowIndex" id="tabledatas" value="#{MB.datas}"  var="item" rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                                         paginator="true" rows="10" styleClass="case-table"  emptyMessage="No records found with given criteria" paginatorPosition="bottom" 
                                         filteredValue="#{mailMB.filteredDAtas}" rowKey="#{item.id}" 
                                         selection="#{MB.selectedAta}" selectionMode="single" >
                                <p:ajax event="rowSelect" update=":form"/>

                                <p:column styleClass="blockable" filterStyle="width: 250px" filterBy="#{item.data} " sortBy="#{item.data}">
                                    <f:facet name="header">
                                        <h:outputText value="Data"/>
                                    </f:facet>
                                    <h:outputText value="#{item.data}"/>
                                </p:column>
                            </p:dataTable>

                    </h:form>  
                    <p:confirmDialog style="position: absolute; size: auto; width: 50px; border-color: blue" id="confirmPurchase"  message="Your Database was successfully created. And contains #{MB.number} Datas "  
                                     appendToBody="true"                                                               
                                     header="Buy Datas List" severity="info" widgetVar="purchase">                          
                        <h:form> 
                            <p:commandButton id="decline" value="Decline" actionListener="#{MB.deleteData()}" update=":form:tabledatas" ajax="true" oncomplete="purchase.hide();" />  
                            <p:commandButton id="Later" value="Later" onclick="purchase.hide();" type="button" />                           
                        </h:form>
                    </p:confirmDialog> 

我错过了什么吗?

actinListener actionListener="#{MB.deleteData()}"中的方法已成功执行,并且数据库的arraylist已从数据库中删除

Bean方法

 public String deleteData() {
    logger.log(Level.SEVERE, "*****delete datas***** ");
    dataBusinessLocal.deleteDatas(datas);
    logger.log(Level.SEVERE, "*****delete Data***** ");
    dataBusinessLocal.deleteData(data);
    return "home";
}

业务方法

@Override
public void deleteDatas(ArrayList<Data> datas) {
    for (int i = 0; i < datas.size(); i++) {
        dataManagerLocal.deleteData(datas.get(i));
    }
}

Dao

 @Override
    public boolean deleteData(Data data) {
        logger.log(Level.SEVERE, "delete data");
        if (findData(data)) {
            this.em.remove(em.merge(data));
            return true;
        }
        return false;
    }

1 个答案:

答案 0 :(得分:1)

显然,您已从数据库中删除了数据,但忘记清除#{MB.datas} bean的@ViewScoped所指向的列表。您的数据表组件只是重新渲染尚未清除的已获取数据。

补救措施非常简单:通过调用datas.clear();,在执行业务逻辑后清除操作方法中的列表。