Board index PrimeFaces Core [RESOLVED] How to keep holded DataTable's page

[RESOLVED] How to keep holded DataTable's page

Components, Ajax Framework, Utilities and More.


Posts: 144
Hey Guys,

I need to keep saved, I mean, to keep holded DataTable's current page so that I can use it later when I come back to it after a page submition.

Well, I noticed that JSF keeps datable's current state cached for partil process. But, in my case I need to go to another page submiting it. Then when I come back I need my datatable get rendered exactly on that page I started. Not sure if I get my case clear to you guys but this is causing my headaches.

Any tips?

Thanks!
Last edited by GuitarBrasil on 17 Oct 2012, 23:16, edited 2 times in total.
PrimeFaces 3.4.2 + JSF 2.1.4 + Tomcat 7.0.14


Posts: 14316
Location: Cybertron

Use page ajax behavior to hook-in paging.
PrimeFaces Lead


Posts: 144
but is that a way to when you come back you back to exactly to the page you were?
PrimeFaces 3.4.2 + JSF 2.1.4 + Tomcat 7.0.14

andyba User avatar
Expert Member

Posts: 1471
Location: Steinfeld, near Bremen/Osnabrück, DE

Or you can use a LazyDataModel managed by a @SessionScoped bean.
PF 3.0.1, PF 3.1, PF 3.2, PF 3.3, PF 3.4.1, PF 3.4.2, PF 3.5
Glassfish 3.1.2.2, Mojarra 2.x, under both Java 6 and Java 7.
If you haven't read the forum rules read them now
My blog: http://onthefaceofthings.blogspot.de/
PrimeFaces Project


Posts: 144
yeah, i got your tips.

but i'm not sure how can I possibly once you come back to datatables after a total submition of my DOM to come back exactly to the datatable's page once selected previously?
PrimeFaces 3.4.2 + JSF 2.1.4 + Tomcat 7.0.14


Posts: 5
I am also trying to do something quite similar.
I need to perform a search, display results in a paginated datatable (I am using LazyDataModel) but I need the table to display directly page 3 (for example).
I don't understand how I can have the datatable to display the third page, how can I trigger what happens when the user clics on the buttons in the pagination handler?
Thanks


Posts: 3565
optimus.prime wrote:
Use page ajax behavior to hook-in paging.


Excellent code sample (click below).
viewtopic.php?f=3&t=18749
Howard

PrimeFaces 4.0, Extensions 0.7.0, Mobile 0.9.5, Push (Atmosphere 1.1 RC2)
TomEE 1.6 (Tomcat 7.0.40), MyFaces Core 2.1.11
JUEL 2.2.6 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache


Posts: 144
smithh032772 wrote:
optimus.prime wrote:
Use page ajax behavior to hook-in paging.


Excellent code sample (click below).
viewtopic.php?f=3&t=18749



Hi,

I'm not sure whether that post can help me in my case. I need to render my datatables exactly on that page which was fired up a html page changed. I'm not sure if my english is good, but imagine this case.

First, you navigate to a particular page on you DataTable then you in that page has a link that send you to another html page (not datatable's page in this case). Then you need go back to the html page that holds your datatable. But you need to get back exactly to that former page in which was fired up that link.

I almost done that using LazyDataModel and passing the current page to the load method so that can be posssible to calculate where I need or where the page I need to go. However I noticed a problem, my datatable's "paginatorTemplate" gets lost because it is expecting to be render on the first page, not in the page I previously calculated in my data model.

So I was wondering if there is a another strategy to achieve that either via javascript or partial update of the datatables but till now, no success!

Any tips?
PrimeFaces 3.4.2 + JSF 2.1.4 + Tomcat 7.0.14


Posts: 144
Hey guys,

I found an elegant solution for my case. What I just needed to do, as Cagatay said, first, I need to hook the "first" attribute so that used to bind it on the datatables via backing bean. Allways I come back to the datable my bean points to the exactly "first" value that according to the manual is "indexes the firsr row to be displayed"!

of course, the first row to be displayed also means the begining of the former current pages.

See what I've done:

in the datatable's backingbean I create a property that holds the "fisrt" element previously hoocked:
@ManagedBean
@SessionScoped
public class DataTableController implements java.io.Serializable {
   protected int first;
        // getters and setters...


My datatables will be like this. I simplified the example so that can more readable!


<p:dataTable id="results-table" var="result"
      ...
      first="#{dataTableController.first}"
                ...
>
<p:ajax event="page" listener="#{dataTableController.onPageChange}"/>
...


Then I hook the last "first" value from the databales on a PageEvent


public void onPageChange(PageEvent event) {
      this.setFirst(((DataTable) event.getSource()).getFirst());
   }



I hope this could help future generation of prime uesers!

Obrigado!!
PrimeFaces 3.4.2 + JSF 2.1.4 + Tomcat 7.0.14


Posts: 14316
Location: Cybertron

Yes, that is what I meant :) Thanks for sharing.

I have implemented a sample persistent page-sort-filter datatable for a client, will share it soon as well in a separate project under examples. Maybe a blog.
PrimeFaces Lead

Next

Return to PrimeFaces Core