开发者

JSF dataTable to display a fixed number of 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-br开发者_运维百科ainer 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜