1

When I am trying to delete an existing row in the data table it deleted successfully. But once I am trying to add a new row in the same session it edit the last row in the table, however it's already added in the list.

<p:dataTable id="AllData" var="itemTypeVar" value="#{itemTypeBean.itemTypesList}"  sortBy="#{itemTypeVar.itemTypeId}"
       editable="true"  paginator="#{common.paginator}" rows="#{common.rows}"  
       paginatorTemplate="#{common.paginatorTemplate}"  
       rowsPerPageTemplate="#{common.rowsPerPageTemplate}" 
       paginatorPosition="#{common.paginatorPosition}" styleClass="sClass ui-datatable-hor-scroll" 
       widgetVar="allData">  

    <p:column  headerText="#{docBundle.delete}" style=" height: auto;width:60px;text-align: center;">

        <p:commandLink action="#{itemTypeBean.delete(itemTypeVar)}" update=":Form_Data:AllData :Form_Mesages"   oncomplete="PF('allData').clearFilters()" />

        <p:commandButton actionListener="#{itemTypeBean.addRecord}" id="add" value= "#{docBundle.add}"  update=":Form_Data :Form_Mesages"  style="margin-top: 5px;" oncomplete="jQuery('.ui-datatable-data tr').last().find('span.ui-icon-pencil').each(function(){jQuery(this).click()}); " />  

bean:

public void delete(InvStpItemType deleted) {
        RequestContext context = RequestContext.getCurrentInstance();
        itemStpTypeCurrent = new InvStpItemType();

        itemStpTypeCurrent = deleted;
        try
        {
            if (itemStpTypeCurrent.getItemTypeId() != 0) {
                invStpItemTypeFacade.remove(deleted);
                 itemTypesList.remove(itemStpTypeCurrent);
                Messages.deleteSuccMsg(this.getLanguage());
            } else {
                itemTypesList.remove(itemStpTypeCurrent);
            }
        }
        catch(Exception ex)
        {
            Messages.errorMsg(getLang(), "canNotDeletedUsedByItems");
        }
}


    public void addRecord() {
        if (!addRecord) {
            addRecord = true;
            itemStpTypeCurrent = new InvStpItemType();
            itemStpTypeCurrent.setActive("A");
            itemTypesList.add(itemStpTypeCurrent);
            Utilities.getLastPagination(":Form_Data:AllData");
        }
        else{  Utilities.getLastPagination(":Form_Data:AllData");}
    }
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
AbouLkhair
  • 175
  • 3
  • 16
  • what is the scope of the bean? the remove looks like a non-ajax call as you use action instead of actionlistener.. also post the datatable code – Maciej Kowalski Feb 02 '17 at 12:57
  • scope is ViewScoped .. ok i will edit it – AbouLkhair Feb 02 '17 at 13:02
  • 1
    @MaciejKowalski: Please stop making this assumption and suggestion. _"the remove looks like a non-ajax call as you use action instead of actionlistener.."_ action works as good with ajax as actionListener, especially (but not limited to) PrimeFaces. See also http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener – Kukeltje Feb 02 '17 at 15:12
  • @Kukeltje that's very useful to me – AbouLkhair Feb 14 '17 at 15:20

1 Answers1

0

I removed ' oncomplete="PF('allData').clearFilters()" ' from my ْXHTML code and reset the datatable from my ْBean code and it works well... if u have a better solution don't hesitate to post it .

 DataTable dataTable = (DataTable)FacesContext.getCurrentInstance().getViewRoot().findComponent(":Form_Data:AllData");
    dataTable.reset();
AbouLkhair
  • 175
  • 3
  • 16