Fórum

Browser Back button - Doesn't call portlet's render method.

thumbnail
Sagar A Vyas, modificado 7 Anos atrás.

Browser Back button - Doesn't call portlet's render method.

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
Hi,

I know most of the browser uses history to load page on Back button, but in my usecase I need to take some action when user click back button of browser ,but I see it is not even calling my portlet render method , I am using LIferay 6.2 EE and Spring portlet.

I am not sure is there any setting in portlet.xml to make sure it will call render method every single time ? or is this something browser related stuff ?

Any pointer would be appreciated.

Thanks,
Sagar Vyas
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: Browser Back button - Doesn't call portlet's render method.

Liferay Legend Postagens: 14914 Data de Entrada: 02/09/06 Postagens Recentes
The portal has no control over the browser when back is used. Most of the time the browser will just show what was there and not make a single call to the server.

Of course you can hack some JS to force this to happen, but honestly you should just reject the use case as it violates web standards.

Users may ask for cars with square wheels - instead of building it for them, just say no.
thumbnail
Sagar A Vyas, modificado 7 Anos atrás.

RE: Browser Back button - Doesn't call portlet's render method. (Resposta)

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
Hi David,

Users may ask for cars with square wheels - instead of building it for them, just say no.
- I am on board on this emoticon

Thanks for reply I see what your'e point is,

Thing becomes bit messy when there is ajax on filter and you need to maintain filter state and result after refresh a page or redirect from other page .

After, I posted this one I was doing some research, some of the big enterprises are doing this thing , for example when you visit amazon website they are having filter (ajax base implementation) but even though they were able to maintain filter and result state on screen on back and forth of browser, one thing I observed that even though there are ajax call they are keep updating URL on browser (that was the game changer , and my clue for soluiton ),

Your'e right browser will not give call back to controller when user clicks on back button, it will read from history and display as it is unless there is any change in URL in browser history emoticon , I see amazon kind of doing the same thing , they are keep updating browser URL on each ajax call and when user click on back button that URL is new in history so it will call controller and then we can do our business logic to maintain that, problem solved.

Now, a million dollar question ,How to do this ? there is concept call pushState with HTML5.


var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
//This will cause the URL bar to display http://localhost:8080/web/guest/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists.


For detail documentation I followed this Solution.

I think this is decent solution,let me know your thought on this if see any backlog in this.

Thank you again.

Thanks,
Sagar Vyas
thumbnail
David H Nebinger, modificado 7 Anos atrás.

RE: Browser Back button - Doesn't call portlet's render method.

Liferay Legend Postagens: 14914 Data de Entrada: 02/09/06 Postagens Recentes
Tampering with the URL can be tricky. Liferay encodes a lot of stuff in there, context relevant to all portlets on the page.
thumbnail
Sagar A Vyas, modificado 7 Anos atrás.

RE: Browser Back button - Doesn't call portlet's render method.

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
David H Nebinger:
Tampering with the URL can be tricky. Liferay encodes a lot of stuff in there, context relevant to all portlets on the page.



Sure, this will not wipe out existing url rather it will append on URL.

Thanks,
Sagar Vyas