JSF dataTable 显示固定行数

发布于 2024-10-04 10:39:11 字数 774 浏览 6 评论 0原文

您好,

上下文是 myFaces 2.0.2,可能还添加了 Tomahawk 20-1.1.10

我创建了一个 dataTable(当前是 h:dataTable,但也可能是 t:dataTable< /code> 使用 Tomahawk)在支持 bean 中显示 List 的某些属性。我通过仅返回列表的 subList 进行分页,并通过单击列标题进行排序。

我需要做的下一件事是确保表始终显示固定数量的行。例如,如果我的页面大小为 5 并且列表中有 12 个项目,则我需要第三页来显示最后两个项目,再加上 3 个空白行。

我尝试用 null 值和带有 null 值的 myObject 实例“填充”subList,但这导致在点击最后一个时出现 ConcurrentModificationException表的页面(即使分页方法仍在添加额外的值,视图仍尝试getDisplayList。)。然后我尝试以相同的方式填充主列表,但随后在我的排序函数上得到了 NullPointer(事后看来这是理所当然的)。另外,当我宁愿在 xhtml 视图中执行此操作时,这些事情都会增加支持者的开销。

(h:/t:)dataTable 确实有一个 rows 属性,但这指定了要显示的最大行数,而不是我需要的最小值。

请问有什么想法吗?

Greetings,

The context is myFaces 2.0.2, possibly also adding Tomahawk 20-1.1.10

I have created a dataTable (currently an h:dataTable, but could also be a t:dataTable using Tomahawk) displaying certain attibutes of a List<MyObject> in a backing bean. I have paging by returning only a subList of the List, and also sorting by click of column headers.

The next thing I need to do is ensure the table always shows a fixed number of rows. For example, if my page size is 5 and I have 12 items in the List, I need page three to show the last two items, plus 3 blank rows.

I have tried to "pad" the subList with both nulls and instances of myObject with null values, but this led to ConcurrentModificationException when hitting the last page of the table (the view was trying to getDisplayList even as the paging method was still adding the extra values.). I then tried padding the main list in the same manner, but then got NullPointers on my sort functions (a no-brainer in hind sight). Plus, these things are all addng overhead in the backer, when I would rather do this in the xhtml view.

(h:/t:)dataTable does have a rows attribute, but this specifies the maximum number of rows to display, not the minimum, as I need.

Ideas, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的那么颓废 2024-10-11 10:39:11

不要填充子列表。填充列表。最好是在将其回收到豆中后立即进行。

Don't pad the sublist. Pad the list. Preferably immediately after retrieving it in the bean.

帅气称霸 2024-10-11 10:39:11

这里的解决方案是使用不为空但属性为空的对象来填充主列表,而不是子列表,并向比较器添加空检查:

if (obj1.getSomeValue() == null) {
    return +1;
}
else if (obj2.getSomeValue() == null) {
    return -1;
}
else {
    // primary sorting code
}

这确保空项目始终出现在最后。作品完美。

BalusC 确实给了我正确的方向,所以我接受他的回答。

The solution here was to pad the MAIN List, rather than the subList, using objects which are not null but whose attributes are null, and to add a null check into the Comparator:

if (obj1.getSomeValue() == null) {
    return +1;
}
else if (obj2.getSomeValue() == null) {
    return -1;
}
else {
    // primary sorting code
}

Which ensures null items always come last. Works perfect.

BalusC did give me the push in the right direction, so I am accepting his answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文