private void removeCacheSessionListener(String uuid) { // Tricky: if onRemove() is called upon session expiration, there might not be an // ExternalContext. But it's fine, // because the session goes away -> all of its attributes go away so we don't have to remove // them below. final ExternalContext.Session session = NetUtils.getSession(XFormsStateManager.FORCE_SESSION_CREATION); if (session != null) { final Map<String, Object> sessionAttributes = session.getAttributesMap(ExternalContext.Session.APPLICATION_SCOPE); final String listenerSessionKey = getListenerSessionKey(uuid); final ExternalContext.Session.SessionListener listener = (ExternalContext.Session.SessionListener) sessionAttributes.get(listenerSessionKey); if (listener != null) { // Remove listener session.removeListener(listener); // Forget, in session, mapping (UUID -> session listener) sessionAttributes.remove(listenerSessionKey); } } }