JSF dataTable 显示固定行数
您好,
上下文是 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 NullPointer
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要填充子列表。填充列表。最好是在将其回收到豆中后立即进行。
Don't pad the sublist. Pad the list. Preferably immediately after retrieving it in the bean.
这里的解决方案是使用不为空但属性为空的对象来填充主列表,而不是子列表,并向比较器添加空检查:
这确保空项目始终出现在最后。作品完美。
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:
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.