Redirect between pages with datatable (primefaces) without losing filters

0

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

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

  • First page: You are responsible for the user selection filter.

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

  • 3rd page: It is related to car details

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

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

I have used the Lazyload context, but I do not think it matters for the case.

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

    
asked by anonymous 11.11.2016 / 18:41

1 answer

0

I've had a similar problem but it was not specifically with PrimeFaces. You can create an entity for the view that contains the filters of your page and / or "sub-entities", in the Spring is known as View Object. Since you create the VO in your controller, just store your filter entity in your session and retrieve when you need it. It's something of the style:

FiltersVO filters = new FiltrosVO ();

/ * ARMAZENA FILTROS * / FacesContext fc = FacesContext.getCurrentInstance (); HttpSession session = (HttpSession) fc.getExternalContext (). GetSession (false); session.setAttribute ("FILTERS", this.filters);

/ * RECOVER FILTERS * / HttpServletRequest request = (HttpServletRequest) req; HttpSession session = (HttpSession) request.getSession (); filters = session.getAttribute ("FILTERS");

    
11.11.2016 / 19:04