Primefaces数据表:撤消筛选后未保留选择

Primefaces数据表:撤消筛选后未保留选择,primefaces,filtering,selection,Primefaces,Filtering,Selection,即时通讯使用: Primefaces v。5.0 JSFV。2.1.3-FCS 我注意到在筛选包含选定行的表时,dataTable中出现了奇怪的行为 首先,我用两个字符完成过滤器字段,这样结果行就不包含所选行。当我从筛选器字段中仅删除一个字符,以便结果行包含以前选定的行时,选择将不启用。删除第二个字符时,选择将再次启用: 筛选前选择的行: 使用两个字符进行筛选,以便结果行不包含所选行: 从筛选器中删除一个字符,以便结果行包含以前选择的行: 删除另一个字符-以前选定的行再次启用了选择:

即时通讯使用:

  • Primefaces v。5.0
  • JSFV。2.1.3-FCS
我注意到在筛选包含选定行的表时,
dataTable
中出现了奇怪的行为

首先,我用两个字符完成过滤器字段,这样结果行就不包含所选行。当我从筛选器字段中仅删除一个字符,以便结果行包含以前选定的行时,选择将不启用。删除第二个字符时,选择将再次启用:

筛选前选择的行:

使用两个字符进行筛选,以便结果行不包含所选行:

从筛选器中删除一个字符,以便结果行包含以前选择的行:

删除另一个字符-以前选定的行再次启用了选择:

我的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>
@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;
  }
}

还有我的豆子

<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>
@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;
  }
}
@ManagedBean
@视域
公共类TestTableBean{
私人名单;
私有列表过滤器列表;
私有TestTableItem currentItem;
{
列表=新的ArrayList();
对于(int i=0;i<5;++i){
添加(新的TestTableItem(i,“hello”+i,10+i));
}
}
公共列表getFilteredList(){
返回过滤器列表;
}
public void setFilteredList(列表filteredList){
this.filteredList=filteredList;
}
公共列表getList(){
退货清单;
}
公共无效集合列表(列表){
this.list=列表;
}
公共TestTableItem getCurrentItem(){
返回当前项目;
}
公共无效setCurrentItem(TestTableItem currentItem){
this.currentItem=currentItem;
}
}
我发现,在
dataTable
中,
selection
属性是基于
value
属性中的列表设置的,
value
属性是基于
filteredValue
属性设置的,如果它不是
null
选择
属性中的对象在设置
筛选值
属性中的列表之前设置,因此可能会导致根据以前的筛选操作设置
选择
的情况,但我不确定


问题是,这种行为是正常的还是bug?如果它是一个bug,有什么解决方法吗?

尝试过PF 5.2甚至5.3-Snapshot吗?为了检查它是否已经是solvedYep,在PF 5.2中对其进行了求解。不过,对于较旧的版本来说,有一些变通方法还是很好的……然后对相关类或javascript进行区分,并创建一个小补丁。事实证明,PF 5.2通过不清除对选定对象的引用来解决这个问题,即使过滤的行不包含以前选定的行。这是很有问题的,因为从控制器的角度来看,选择仍然处于启用状态(即,在选定行上触发某些操作的按钮仍然处于活动状态)。由于filteredValue属性是在jsf生命周期的呈现阶段设置的,所以很难通过编程来区分行选择。。。