我想限制记录的编号显示在。
之下以下是代码段。
//用于显示复选框的过滤器类
class Filter {
public String filterValueName;
}
//在BEAN下声明的字段
public List<String> filterValuesChecked;
public List<Filter> filterValues;
// XHTML迭代列表
<h:selectManyCheckbox value="#{fltrResult.filterValuesChecked}" layout="pageDirection" >
<f:selectItems value="#{fltrResult.filterValues}" var="fltrVal"
itemLabel="#{fltrVal.filterValueName}"
itemValue="#{fltrVal.filterValueName}" />
</h:selectManyCheckbox>
上面的代码工作得很好,但是这里的问题是List filterValues包含1000条记录,我想只显示5-10个复选框,然后在Link之后显示整个列表。
我浪费了很多时间在谷歌找出解决方案,但没有得到它。 请提供我如何实现相同的方式
先谢谢, 奇拉格
答案 0 :(得分:0)
试试这个:
在Bean中:
private final int MAXNUMBER = 10; // e.g.
public List<String> filterValuesChecked;
public List<Filter> filterValues;
// With a fixed limit:
public List<Filter> getRestrictedFilterValues(){
return this.filterValues.subList(0, MAXNUMBER);
}
// With a dynamic limit:
public List<Filter> getRestrictedFilterValues(int maximum){
return this.filterValues.subList(0, maximum);
}
在xhtml中:
<h:selectManyCheckbox value="#{fltrResult.filterValuesChecked}" layout="pageDirection">
<f:selectItems value="#{fltrResult.getRestrictedFilterValues()}" var="fltrVal"
itemLabel="#{fltrVal.filterValueName}"
itemValue="#{fltrVal.filterValueName}" />
</h:selectManyCheckbox>
原因是,您可以在getRestrictedFilterValues
- 方法中使用任何选择算法。
补充:在这种情况下考虑使用(自定义)转换器,因此您不必处理字符串,但可以直接获取Filter
- 对象作为结果(=&gt; public List<Filter> filterValuesChecked;
)。见http://www.tutorialspoint.com/jsf/jsf_customconvertor_tag.htm