How to check if there is an active session in a JSF page?
- by Roberto de Santis
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