Is there any event hadling mechanism in JSF 2 after a page has been rendered completely? I want to invalidate the session of a user once he reaches the last page of my application and the page has been rendered completely??
-
why wait until page is rendered? can't you use preRenderView event? – damian Jun 08 '12 at 13:39
-
actually I can not as it will invalidate the session and the page will not be able to display the content which it is supposed to display from backing bean propertied which is session scoped. – user1220373 Jun 08 '12 at 15:40
-
I don't know a JSF native way of doing this, but how about adding a script in the 'onload' body attribute, that programmatically clicks a hidden button, which executes the method you need to run? – damian Jun 09 '12 at 15:59
1 Answers
Have a look here: Link. Maybe you can try invalidating the session on event PreRenderComponentEvent
(After a component has been rendered), although the name and description seem inconsistent.
If it does not work, you can try with the workaround by indirect navigation to your target page. Initialy you navigate to some dummy JSF page, which will invalidate the session (postconstruct method, or system event listener), then trigger the redirection to your target JSF page. Help for redirection. If you need this behaviour in several places, you can also generalize the intermediate JSF by passing the target page as a parameter.
EDIT: Have you tried invalidating the session in method annotated with @PreDestroy inside a RequestScoped bean? In case if it works: I am not sure if JSF guarantees to call the predestroy methods before the new request is made.