【问题标题】:how to limit the records to display under <h:selectManyCheckbox>如何限制在 <h:selectManyCheckbox> 下显示的记录
【发布时间】:2014-10-15 15:05:31
【问题描述】:

我想限制在.下显示的记录数。

这里是代码sn-p。

//用于显示复选框的过滤器类

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 个复选框,然后链接以可视化整个列表。

我在谷歌上浪费了很多时间来找出解决方案,但没有得到它。 请提供我如何实现相同的方法

提前致谢, 奇拉格

【问题讨论】:

  • 您可以创建一个备用 List&lt;Filter&gt; 来存储要显示的值。
  • 我对你有个想法。也许您应该尝试放置按钮而不是 selectManyCheckBox。该按钮将显示对话框,将数据表放在那里,以便用户可以拿起这些项目。由于您将拥有 dataTable,您还可以实现延迟加载,并且您正在搜索/单击/尝试显示多少记录并不重要:)
  • 就像@LuiggiMendoza - 你必须自己做入围名单。没有开箱即用的属性可以为您缩短列表
  • 感谢@LuiggiMendoza:我正在考虑“渲染”,如果我可以使用一些可能有帮助的 逻辑。
  • 渲染在这里帮不了你。最好准备子集并将其用于您的页面。

标签: jsf jsf-2 primefaces spring-webflow jsf-2.2


【解决方案1】:

试试这个:

在豆子里:

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-Objects 作为结果(=> public List&lt;Filter&gt; filterValuesChecked;)。见http://www.tutorialspoint.com/jsf/jsf_customconvertor_tag.htm

【讨论】:

  • 好主意,是的!我知道自定义转换器。谢谢...它会为我工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多