Primefaces DataTable:撤消过滤后未保留选择

时间:2015-07-13 15:32:49

标签: primefaces filtering selection

我正在使用:

  • Primefaces v.5.0
  • JSF v.2.1.3-FCS

在使用选定行过滤表时,我注意到dataTable中的奇怪行为。

首先,我满足两个字符的过滤字段,以便结果行不包含选定的行。当我从过滤器字段中仅删除一个字符以使结果行包含先前选定的行时,不会启用该选择。当我删除第二个字符时,再次启用选择:

过滤前选定的行:
selected row before filtering

使用两个字符进行过滤,以便结果行不包含选定的行: Filtering with two characters

从过滤器中删除一个字符,以便结果行包含以前选定的行: Deleting one character

删除另一个字符 - 之前选择的行再次启用选择: Deleting another character

我的 xhtml

<h:form>
            <p:dataTable value="#{testTableBean.list}" 
                filteredValue="#{testTableBean.filteredList}" 
                selectionMode="single"
                selection="#{testTableBean.currentItem}" var="item"
                rowKey="#{item.id}">

                <p:column headerText="ID">
                    <h:outputText value="#{item.id}" />
                </p:column>
                <p:column headerText="name" filterBy="#{item.name}"
                    sortBy="#{item.name}">
                    <h:outputText value="#{item.name}" />
                </p:column>
                <p:column headerText="value">
                    <h:outputText value="#{item.value}" />
                </p:column>
            </p:dataTable>
</h:form>

我的 bean

@ManagedBean
@ViewScoped
public class TestTableBean {

  private List<TestTableItem> list;
  private List<TestTableItem> filteredList;
  private TestTableItem currentItem;

  {
    list = new ArrayList<TestTableItem>();
    for (int i = 0; i < 5; ++i) {
      list.add(new TestTableItem(i, "hello" + i, 10 + i));
    }
  }

  public List<TestTableItem> getFilteredList() {
    return filteredList;
  }

  public void setFilteredList(List<TestTableItem> filteredList) {
    this.filteredList = filteredList;
  }


  public List<TestTableItem> getList() {
    return list;
  }

  public void setList(List<TestTableItem> list) {
    this.list = list;
  }

  public TestTableItem getCurrentItem() {
    return currentItem;
  }

  public void setCurrentItem(TestTableItem currentItem) {
    this.currentItem = currentItem;
  }
}

我发现,dataTable selection属性是根据value属性列表设置的,value属性是基于{{1}设置的}} attribute-如果它不是filteredValue。来自null属性的对象在设置selection属性的列表之前设置,因此可能导致基于先前过滤器操作设置filteredValue的情况,但我不确定。< / p>

问题是,这种行为是正常的还是一个错误?如果它是一个bug,是否有任何变通方法?

0 个答案:

没有答案
相关问题