在另一个数据表中删除后,行不会从数据表中删除

时间:2015-04-21 13:12:11

标签: primefaces datatable

我需要你帮助将删除的行从datatable1移到datatable2。我正在使用Drag&删除PrimeFaces中的数据表。一旦我从datatable1拖动了行并将其放在datatable2中,该行将保留在datatable1中,它将被添加到datatable2中,应该从datatable1中删除它。我的代码如下:

    private List<PendingRequests> listPendingRequests;

    private List<PendingRequests> droppedRequests;

    private PendingRequests selectedRequest;


    @PostConstruct

       public void init() {

           droppedRequests = new ArrayList<PendingRequests>();

           listPendingRequests= new ArrayList<PendingRequests>();

       }

public void onRequestDrop(DragDropEvent ddEvent) {

PendingRequests car = ((PendingRequests) ddEvent.getData());

droppedRequests.add(car);

listPendingRequests.remove(car);
           RequestContext.getCurrentInstance().update("Pendings:PendingRequests");

                  }     

以下是我的xhtml:

<script type="text/javascript">

  function handleDrop(event, ui) {

  var droppedRequests = ui.draggable;

  droppedRequests.fadeOut('fast');

  }

 </script>

<h:form id="Requests">

<p:fieldset id="Pendings" legend="Pending Requests">

<p:dataTable id="PendingRequests" var="hr" value="#{hrd.pendingRequests}" >

  <p:column style="width:20px">

<h:outputText id="dragIcon" styleClass="ui-icon ui-icon-arrow-4"/>

                                <p:draggable for="dragIcon" revert="true" helper="clone"/>
 </p:column>

</p:dataTable>

</p:fieldset>

<p:fieldset id="Closed" legend="Closed Requests" style="margin-top:20px">

<p:outputPanel id="dropArea">

<h:outputText value="!!!Drop here!!!" rendered="#{empty hrd.droppedRequests}"
                            style="font-size:24px;"/>

<p:dataTable id="ClosedRequests" var="chr" value="#{hrd.droppedRequests}"                                      rendered="#{not empty hrd.droppedRequests}">

<p:column headerText="Request No.">

<h:outputText value="#{chr.reqNo}"/>

 </p:column>

 </p:dataTable>

</p:outputPanel>

</p:fieldset>

  <p:droppable for="Closed" tolerance="touch" activeStyleClass="ui-state-highlight" datasource="PendingRequests" onDrop="handleDrop">

  <p:ajax listener="#{hrd.onRequestDrop}" update="dropArea PendingRequests"/>

 </p:droppable>

1 个答案:

答案 0 :(得分:0)

解决方案是将arraylist保存在init方法中并运行它@postConstruct