开发者

Display all rows in tomahawk paginated, sortable datatable

开发者 https://www.devze.com 2023-02-19 06:28 出处:网络
I\'m trying to create a paginated, sortable datatable using MyFaces.The sorting works fine; I can click on a column header and it will sort the data based on the column.Also the pagination works fine

I'm trying to create a paginated, sortable datatable using MyFaces. The sorting works fine; I can click on a column header and it will sort the data based on the column. Also the pagination works fine for the most part. The datatable will split itself appropriately with some number of items per page. In addition, I want the user to be able to change the number of items displayed per page. Again, this seems to be working until I want all of the items displayed on one page.

According to this reference (also here), if you set the "rows" attribute of t:datatable to "0", it will display the remaining rows in the table. However, when I try this, I get an exception that includes this message:

javax.faces.FacesException - You need to set a value to the 'rows' attribute of component 'myComponent'

I'm trying to set the number of items per page using an attribute in a backing bean. My t:datatable looks like this:

<t:dataTable id="myComponent" var="cur"
    value="#{backingBean.list}" sortAscending="#{backingBean.ascending}"
    sortColumn="#{backingBean.sortColumn}" sortable="true"
    styleClass="myClass" rowClasses="oddRow,evenRow"
    rows="#{backingBean.itemsPerPage}" preserveDataModel="false">
    <!-- data here -->
</t:datatable>

Later, I have a t:dataScroller to control the pagination:

<t:dataScroller id="pageNavigation" for="myComponent"
    paginatorActiveColumnStyle="font-weight:bold;"
    renderFacetsIfSinglePage="false" 
    binding="#{backingBean.scroller}" 
    paginator="true" >
    <!-- facets here -->
</t:dataScroller>

Then, I have a h:selectOneMenu to select the number of items per page

<h:selectOneMenu id="myScroller"
    value="#{backingBean.itemsPerPage}"
    required="true" onchange="this.form.submit();"
    valueChangeListener="#{backingBean.updateItemsPerPage}">
    <f:selectItems value="#{backingBean.itemsPerPageArray}" />
</h:selectOneMenu>

My backing bean looks something like this:

public class BackingBean {

    private boolean ascending;
    private Long itemsPerPage;
    private String sortColumn;
    private ArrayList<SelectItem> itemsPerPageArray;
    private ArrayList<SomeObject> list;  // data for table
    private HtmlDataScroller scroller;

    // constructors, getters, setters, and other stuff here

    public void updateItemsPerPage(ValueChangeEvent valueChangeEvent) {
        itemsPerPage = (Long) valueChangeEvent.getNewValue();
        resetScrollerIndex();
    }

    private void resetScrollerIndex() {
        if (scroller!=null && scroller.isPaginator())
            scroller.getUIData().setFirst(0);
    }

    // called in constructor
    private void constructItemsPerPageArray() {
        itemsPerPageArray = new ArrayList<SelectItem>();
        itemsPerPageArray.add(new SelectIt开发者_运维问答em(new Long(10), "10"));
        itemsPerPageArray.add(new SelectItem(new Long(50), "50"));
        itemsPerPageArray.add(new SelectItem(new Long(100), "100"));
        itemsPerPageArray.add(new SelectItem(new Long(0), "All"));
    }
}

To sum up, when I select the "All" item from the h:selectOneMenu, I get the exception mentioned above. Hopefully, I've included an appropriate level of detail. Thanks!


Alright, I think I found the answer...

If I remove the first line from the updateItemsPerPage method, the problem is fixed. The method now looks like:

public void updateItemsPerPage(ValueChangeEvent valueChangeEvent) {
    resetScrollerIndex();
}

It thought I had tried that...

0

精彩评论

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