0

拖放和排序对我来说工作正常,但过滤不能正常工作(过滤只能工作一次)。如果有人得到解决方案,请帮助我。

索引.xhtml

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"     
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <script type="text/javascript">
           function handleDrop(event, ui)
           {
              var droppedCar = ui.draggable;
              droppedCar.fadeOut('fast');
           }
         </script>
    </h:head>
    <h:body>
        <h:form id="carForm">
                <p:dataTable id="availableCars" var="car" value="#{Report.field1}">

                    <p:column sortBy="#{car.values}" filterBy="#{car.values}" headerText="Properties"> 
                              <h:outputText id="dragIcon" value="#{car.values}" /> 
                              <p:draggable for="dragIcon" revert="true" /> 
                           </p:column> 
                 </p:dataTable>             
            <p:fieldset id="selectedCars" style="margin-top:20px"> 
                   <p:outputPanel id="dropArea"> 
                       <h:outputText value="!!!Drop here!!!" rendered="#{empty Report.field2}" style="font-size:24px;" /> 
                       <p:dataTable var="car" value="#{Report.field2}" rendered="#{not empty Report.field2}"> 
                               <p:column headerText="Color"> 
                                   <h:outputText value="#{car.values}" /> 
                               </p:column>                                         
                        </p:dataTable> 
                   </p:outputPanel> 
           </p:fieldset> 
           <p:droppable for="selectedCars" tolerance="touch" activeStyleClass="ui-state-highlight" datasource="availableCars" onDrop="handleDrop"> 
                  <p:ajax listener="#{Report.onCarDrop}" update="dropArea availableCars" /> 
            </p:droppable> 
        </h:form>
    </h:body>
</html>

豆豆是

临时报告.java

    public class tempReport
{
    public String values;
    public tempReport(String values)
    {
        this.values=values;
    }
    public String getValues()
    {
        return values;
    }
    public void setValues(String values)
    {
        this.values=values;
    }   
}

报告生成器.java

    import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.event.DragDropEvent;
@ManagedBean(name="Report")
@RequestScoped
public class ReportGenerator implements Serializable
{
    static List<tempReport> field1=new ArrayList<tempReport>(),field2=new ArrayList<tempReport>();
    static int i=1;
    public ReportGenerator()
    {

        if(i==1)
        {
        field1=new ArrayList<tempReport>();
        field2=new ArrayList<tempReport>();
        field1.add(new tempReport("one"));
        field1.add(new tempReport("two"));
        field1.add(new tempReport("three"));
        field1.add(new tempReport("four"));
        field1.add(new tempReport("five"));
        field1.add(new tempReport("six")); 
        i++;
        }
    }
    public List<tempReport> getField1()
    {
        return field1;
    }
    public void setField1(List<tempReport> field1)
    {
        this.field1=field1;
    }
     public List<tempReport> getField2()
    {
        return field2;
    }
    public void setField2(List<tempReport> field2)
    {
        this.field2=field2;
    }
    public void onCarDrop(DragDropEvent ddEvent)
     {
        tempReport car = ((tempReport) ddEvent.getData());
        int x=0;
        for(tempReport item: field2)
        {
            if(item==car)
                x=1;
        }
        if(x==0)
        field2.add(car);       
    } 
  }

谢谢

4

1 回答 1

0

我回到 primefaces 3.3.1,因为它在 3.3.1 中工作正常,在 3.4 和 3.4.1 中无法正常工作

谢谢

于 2012-10-24T14:28:46.450 回答