junior developper
junior developper

Reputation: 448

datatable is not updating

After deleting all the elements of a dataTable via confirmDialog the data table is not updated and remains filled

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

Am i missing something?

the method in the actinListener actionListener="#{MB.deleteData()}" was executed successfully and the datas' arraylist are removed from the database

the Bean Method

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

the business method

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

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

Upvotes: 0

Views: 100

Answers (1)

skuntsel
skuntsel

Reputation: 11742

Apparently you have removed the data from the database but forgot to clear the list as pointed by #{MB.datas} of your @ViewScoped bean. Your datatable component simply rerenders the already fetched data that's simply not cleared.

The remedy is quite simple: clear the list in your action method after business logic has been executed, by calling datas.clear();.

Upvotes: 1

Related Questions