Manorrock.com / Demo JSF

JSF Horizontal AJAX Paging demo

How to get this working

To get this working on your own page, look below for the example snippet used to get the demo on this page working.

<h:form id="form1">
    <h:messages/>
    <h:dataTable id="table1" value="#{pagerBean.items}" var="item">
        <h:column>
            <h:outputText value="#{item}"/>
        </h:column>
    </h:dataTable>
    <paging:horizontalAjaxPager
        xmlns:paging="http://java.sun.com/jsf/composite/com.manorrock.jsf.paging"
        ajaxRender=":form1:table1"
        firstActionListener="#{pagerBean.doFirstEvent}"
        previousActionListener="#{pagerBean.doPreviousEvent}"
        nextActionListener="#{pagerBean.doNextEvent}"
        lastActionListener="#{pagerBean.doLastEvent}"
        />
</h:form>
                    

For the demo we need some java code to make it work, see the code below.

    /**
     * Stores the items.
     */
    private List items = new ArrayList();

    /**
     * Stores the index.
     */
    private int index = 0;

    /**
     * Handle the next event.
     */
    public void doFirstEvent(ActionEvent event) {
        index += 0;
        loadItems();
    }

    /**
     * Handle the next event.
     */
    public void doLastEvent(ActionEvent event) {
        index += 990;
        loadItems();
    }

    /**
     * Handle the next event.
     */
    public void doNextEvent(ActionEvent event) {
        index += 10;
        loadItems();
    }

    /**
     * Handle the previous event.
     */
    public void doPreviousEvent(ActionEvent event) {
        index -= 10;
        loadItems();
    }

    /**
     * Get the items.
     *
     * @return the items.
     */
    public List getItems() {
        return items;
    }

    /**
     * Load the items.
     */
    private void loadItems() {
        items = new ArrayList();
        for(int i=0; i<10; i++) {
            items.add(new Long(index+i));
        }
    }
                    
Actual demo

Click on the previous and next buttons and see magic happen!

0
1
2
3
4
5
6
7
8
9


Up