JSF Phase Listener redirect form not iframe

拥有回忆 提交于 2019-12-23 19:15:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!