问题
I have this PhaseListener that checks whether the user is still logged in or not after restoring a view. If the session has expired, then I want the entire form to redirect to the /login.jsf page but instead it only redirects the iframe within.
Basically, this is my code in the afterPhase() method:
if (isWebUserLogonOk(session)) {
NavigationHandler nh = faces.getApplication.getNavigationHandler();
nh.handleNavigation(faces, null, "loggedoff");
}
Where loggedoff is a navigation case that takes you to login.jsp page.
The redirect is done as expected but in this particular case I want it to be done for the entire form and not the iframe (JSF rookie talking here).
回答1:
If you do not want to have a page (e.g. the login page) shown in an iFrame, a javascript framekiller should solve this.
Add the following code into your login pages head and try again:
<script type="text/javascript">
if(top != self) top.location.replace(location);
</script>
It easily reloads the current page as top page.
Hope it helps...
来源:https://stackoverflow.com/questions/21006840/jsf-phase-listener-redirect-form-not-iframe