Thursday, December 27, 2012

How to display list with paging without refreshing page

This article depicts the usage of paging in a seam/jsf application without refreshing the page when navigating between pages.

The main points are:

  1. using an outputpanel
  • <a:outputPanel id="studentPanel" ajaxRendered="true">
  1. using a c:foreach to iterate over the collection (do not use a:repeat or ui:repeat since they make multiple calls to the backing bean/called method)
  • <c:forEach items="#{topStudents}" var="topStudent">
for the pagination use a:commandButton inside an a:form
<a:form >
<a:commandButton action="#{topStudentManager.getResultByPage(1)}" value="rre1" reRender="studentPanel">
<s:conversationPropagation type="join"></s:conversationPropagation>
</a:commandButton>
<a:commandButton action="#{topStudentManager.getResultByPage(2)}" value="rre2" reRender="studentPanel"/>

</a:form>

topStudents is a factory:
@Factory(value = "topStudents2")
    public List<TopStudent> initializeTopStudent() {       
//query DB and set topStudents
    //set collection in context
    //Contexts.getConversationContext().set("topStudents2", topStudents);    
        return topStudents;
    }

// compute paging
public void getResultByPage(Integer page){
//set currentpage to page
//initiliase collection topStudents
//compute paging from collection
//set paging in context variable
//Contexts.getConversationContext().set("topStudentPages", topStudents);

}

No comments:

Post a Comment