-
1. Re: True pagination using AbstractList<E>
michpetrov Aug 13, 2014 9:52 AM (in response to snowhite)Hi,
can you share your code? I think the general approach should still work.
-
2. Re: Re: True pagination using AbstractList<E>
snowhite Aug 13, 2014 2:30 PM (in response to michpetrov)Thanks for the reply. I attached my code here.
-
PagedList.java 670 bytes
-
LineItemsDataModel.java 1.1 KB
-
ext_table.xhtml.zip 802 bytes
-
-
3. Re: True pagination using AbstractList<E>
michpetrov Aug 14, 2014 7:39 AM (in response to snowhite)That works for me, providing you have all the methods from LineItemsDataModel implemented (though I've used @ManagedBean instead of the Seam annotation).
-
4. Re: True pagination using AbstractList<E>
snowhite Aug 14, 2014 1:24 PM (in response to michpetrov)I tried using @ManagedBean but its not working either. Can you please share your code, thanks.
-
5. Re: Re: True pagination using AbstractList<E>
michpetrov Aug 18, 2014 4:21 AM (in response to snowhite)bean
@ManagedBean @SessionScoped public class LineItemsDataModel implements Serializable{ private static final long serialVersionUID = 1L; int page = 0; private int total; private List<String> lstLineItems; private int itemsPerPage = 6; public int getItemsPerPage() { return itemsPerPage; } public void setItemsPerPage(int itemsPerPage) { this.itemsPerPage = itemsPerPage; } private List<String> list = new ArrayList<String>(); private Logger log = Logger.getLogger("lists"); public LineItemsDataModel() { list.add("aaa"); list.add("aab"); list.add("aac"); list.add("aad"); list.add("aae"); list.add("aaf"); list.add("aag"); list.add("aah"); list.add("bba"); list.add("bbb"); list.add("bbc"); list.add("bbd"); list.add("bbe"); list.add("bbf"); list.add("bbg"); list.add("bbh"); fetch(); } public void fetch(){ total = 30; //returns total count of items int limit = itemsPerPage; int startRow = (getPage()-1)*itemsPerPage + 1; if(startRow>total){startRow=1;page=1;}; List<String> l = list.subList(startRow, startRow + limit); //getList(startRow,limit); //returns only single page list setLstLineItems(new PagedList<String>(l,total,itemsPerPage)); } public String actionOnPageChange(DataScrollEvent event) { String val = event.getNewScrolVal(); log.info(val); return val; } public int getPage() { if(page == 0) return 1; return page; } public void setPage(int page) { this.page = page; fetch(); } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } public List<String> getLstLineItems() { return lstLineItems; } public void setLstLineItems(List<String> lstLineItems) { this.lstLineItems = lstLineItems; } }
page:
<h:form id="form"> <rich:extendedDataTable value="#{lineItemsDataModel.lstLineItems}" var="item" id="table" rows="#{lineItemsDataModel.itemsPerPage}"> <rich:column> <f:facet name="header"> <h:outputText value="Ref Number" /> </f:facet> <h:outputText value="#{item}" /> </rich:column> <rich:column> <f:facet name="header"> <h:outputText value="Order Number" /> </f:facet> <h:outputText value="#{item}" /> </rich:column> <rich:column> <f:facet name="header"> <h:outputText value="Company Name" /> </f:facet> <h:outputText value="#{item}" /> </rich:column> <f:facet name="footer"> <rich:dataScroller render="table,sumScr1" execute="table" scrollListener="#{lineItemsDataModel.actionOnPageChange}" id="sumScr1" maxPages="5" for="table" page="#{lineItemsDataModel.page}"> <f:facet name="first"> <h:outputText value="First" /> </f:facet> <f:facet name="last"> <h:outputText value="Last" /> </f:facet> </rich:dataScroller> </f:facet> </rich:extendedDataTable> </h:form>
-
6. Re: True pagination using AbstractList<E>
snowhite Sep 17, 2014 7:03 PM (in response to michpetrov)Hi Petrov,
I apologize for the delay in my response. I really appreciate your help with this. It worked for me. I realized the only difference between yours and mine was that you are calling fetch() method in the constructor itself.
Now I have one more issue with it. If I go to any page (say page 2 or 3 etc) constructor is being called and the page value is always set to 1. However actionOnPageChange() method is getting called after that with proper page values set. Is there a way to avoid this? I dont understand why the constructor is being called again that means LineItemsDataModel is again getting created for every page? I tried by setting the Scope to Session (@SessionScroped) as well but no luck. I also tried caching the values but with no luck. Let me know your valuable thoughts on this.
Thanks
-
7. Re: True pagination using AbstractList<E>
snowhite Sep 18, 2014 2:24 PM (in response to snowhite)1 of 1 people found this helpfulI think I figured out why it was calling the constructor on every page. Even though LineItemsDataModel scrope is set to Session Scope (@SessionScoped) I see in the console it is set to Event Scope. When I used Seam annotation to set the Scope (@Scope (ScopeType.SESSION) or @Scope (ScopeType.PAGE)) it is working fine. Now the constructor is not called on every page click.
I appreciate your time in looking into this.
Thanks,