I have an JSF Primefaces application which on one page shows an iFrame. In this iFrame the user can work for quite a while, afterwards he can press a button which navigates to one of my JSF handled pages. I implemented this using the window.parent.postMessage
event, this works well.
But still there remains one problem: While working in the iFrame, the Session times out and the user gets redirected to the login screen.
I already tried using <p:poll interval="1500" listener="#{bean.interact}"/>
with
public String interact() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getSession(false);
return null;
}
in order to keep the session alive. In my interact function I tried different things. I read in other StackOverflow posts that getting the session should be enough to keep it open.
Debugging the function shows that session.getLastAccessedTime()
is updated every time the poll is executing. The session ID is always the same.
But still, after my defined session timeout, the user gets redirected to the login screen the moment the poll is fired.
My .xhtml file hosting the frame looks as follows:
<ui:define name="content">
<h:form>
<p:remoteCommand name="finish" action="#{bean.finish()}"/>
<p:remoteCommand name="back" action="#{bean.back()}"/>
<script type="text/javascript">
window.addEventListener('message', (e) => {
if(e.data === 'finished') {
finish();
} else if(e.data === 'back') {
back();
}
});
</script>
<iframe src="https://myUrl/#{bean.queryParameterEncrypted()}"/>
<p:poll interval="1500" listener="#{bean.interact}"/>
</h:form>
</ui:define>