How to check if there is an active session in a JSF page?
Posted
by
Roberto de Santis
on Stack Overflow
See other posts from Stack Overflow
or by Roberto de Santis
Published on 2011-01-16T14:58:16Z
Indexed on
2011/01/16
18:53 UTC
Read the original article
Hit count: 208
Hi, there is a way to check if there is an active session directly in jsf page? I have try this but it doesn't work:
<p:ajaxStatus onerror="#{session == null ? 'idleDialog.show();' : null}"
thank you in advance
@Update I have see that onerror isn't fired even if viewExpiredException occurr.
@Update 1 Ok i have implemented something that may work:
<h:form>
<p:idleMonitor timeout="10000"
idleListener="#{idleMonitorController.idleListener}"
onidle="sessionPoll.stop();idleDialog.show();"/>
</h:form>
<p:dialog header="Sessione scaduta per inattività "
widgetVar="idleDialog"
modal="true"
width="400">
<h:outputText value="Sessione scaduta" />
<h:button value="Ripristina Sessione"
onclick="idleDialog.hide();sessionPoll.start();" />
</p:dialog>
<h:form prependId="false">
<p:poll widgetVar="sessionPoll"
interval="1"/>
</h:form>
and this is the listner:
public void idleListener(IdleEvent event) {
System.out.println("aaaa");
final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getSession(false).invalidate();
}
now the only problem is that the session.invalidate doesn't work
© Stack Overflow or respective owner