deltaspike

un-scope @ViewAccessScoped Beans on Tab close


I have a JSF-App with two @ViewAccessScoped Beans and two Pages/Views, one Bean for a Search, on Bean for details. The details Bean references the @ViewAccessScoped so the data available when I go back to the Search. No other CDI-References. The WindowRenderMode is ClientWindowRenderMode.CLIENTWINDOW, no further configuration.

This works quite well so far. The Beans get un-scoped if i go to another page or logout. One Problem I Experienced: When I open my details page in a new Browser tab, two new Beans are created, which is the expected Behavior. But when i close the tab, the Beans are still there. I guess the Server doesn't get notified when a tab get's closed.

  1. Is there a built-in solution in deltaspike i can use to detect tab clsoes?
  2. Is there a Timeout for Beans with @ViewAccessScoped (beside the Session-Timeout)?
  3. If there isn't a bulit-in solution: How can i programmatically un-scope my Beans? Preferably un-scope all Beans connected to that tab (=same Window-ID) (I'd detect the close my self with JavaScript and call a Bean-Method on close)

Solution

    1. No, as it's not possible to catch a "tab close" event in JS. See: javascript detect browser close tab/close browser

    2. It was available in CODI but it was not migrated to DeltaSpike. See: https://issues.apache.org/jira/browse/DELTASPIKE-437

    3. You can do it via the WindowContext API:

      @Inject private org.apache.deltaspike.core.spi.scope.window.WindowContext windowContext;
      
      public void closeIt() {
          windowContext.closeWindow("myWindowId");
      }