Redirect between pages with datatable(primefaces) without losing filters

Asked

Viewed 126 times

0

I have 3 pages and they are responsible for fetching objects in my databases based on the first page selection filter.

My website is about car ads and has the following structure:

  • 1st page: Responsible for user selection filter.

  • 2nd page: This is the datatable page with the first page filter results.

  • 3rd page: It is related to the car details

I used @SessionScoped in my project to be able to do what I want and "got" that way, but the problem is that when I’m on the third, fourth, fifth page of the datatable, by clicking on a row of ad details and returning to the page of datatable, instead of it returns to the page I was on, it returns to the first no matter where it is. It always returns to the first page...

Because of that, I tried to change my bean to use @ViewScoped. I thought it would solve my problem, but when I return from the third page of the site to the second, the datatable loses filter data(as @ViewScoped).

I’ve been using the context Lazyload, but I guess it doesn’t matter to the case.

My need is for the user to be able to click on an ad and if he wants to get back to exactly the page he was on, he can.

1 answer

0

I’ve had a similar problem before, but not specifically with Primefaces. You can create an entity for the view that contains the filters of your page and/or "sub-entities", in Spring it is known as View Object. As you create the VO in your controller, just store in your session your filter entity and recover when needed. It’s kind of like:

Filter filters = new Filter();

/* STORES FILTERS */ Facescontext Fc = Facescontext.getCurrentInstance(); httpsession Session = (Httpsession) Fc.getExternalContext(). getSession(false); Session.setAttribute("FILTERS", this.filters);

/* RECOVERS FILTERS */ httpservletrequest request request = (Httpservletrequest) req; httpsession Session = (Httpsession) request.getSession(); filters = Session.getattribute("FILTERS");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.