ICEfaces
  1. ICEfaces
  2. ICE-6826

Add support for @PostConstruct and @PreDestroy annotations for window-scoped beans

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.1, EE-2.0.0.GA
    • Fix Version/s: 2.1-Beta, 3.0
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      ICEfaces
    • Assignee Priority:
      P2
    • Affects:
      Documentation (User Guide, Ref. Guide, etc.)

      Description

      Upon session expiry the WindowScopeManager can check the session for existence of window scoped beans and scan for the @PostConstruct and @PreDestroy annotations and invoke the appropriate methods if present.

        Issue Links

          Activity

          Jack Van Ooststroom created issue -
          Ken Fyten made changes -
          Field Original Value New Value
          Salesforce Case []
          Fix Version/s 2.1 [ 10241 ]
          Affects [Documentation (User Guide, Ref. Guide, etc.)]
          Assignee Priority P3
          Assignee Jack van Ooststroom [ jack.van.ooststroom ]
          Ken Fyten made changes -
          Salesforce Case []
          Assignee Priority P3 P2
          Jack Van Ooststroom made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #25012 Tue Jul 12 13:24:22 MDT 2011 jack.van.ooststroom Partial Fix for JIRA ICE-6826 : Add support for @PostConstruct and @PreDestroy annotations for window-scoped beans
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/application/SessionExpiredListener.java
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/application/WindowScopeManager.java
          Jack Van Ooststroom made changes -
          Link This issue depends on ICE-7055 [ ICE-7055 ]
          Hide
          Jack Van Ooststroom added a comment -

          The @PostConstruct and @PreDestroy annotation support on CustomScoped beans already seemed to be partially supported. Though I haven't looked into the JSF source code, I suspect the following two calls in WindowScopeManager to help out with the current support of this:

          • facesContext.getApplication().publishEvent(facesContext, PostConstructCustomScopeEvent.class, context);
          • facesContext.getApplication().publishEvent(facesContext, PreDestroyCustomScopeEvent.class, context);

          These calls and the locations in the code where these calls are made seem to explain the 2 working scenarios:

          • Whenever a window scoped bean is created the @PostConstruct on this window scoped bean gets invoked
          • Whenever a window scoped bean is abandoned but the session hasn't expired yet, the @PreDestroy on this window scoped bean gets invoked

          The one missing case seem to be the invocation of @PreDestroy upon session expiry for all remaining window scoped beans in the session. However, upon session expiry you're not guaranteed to have a FacesContext. Therefore the similar mechanism cannot be used. Instead, the SessionExpiredListener now invokes the newly created WindowScopeManager.disposeWindows(HttpSession) upon session expiry:

          public void sessionDestroyed(HttpSessionEvent httpSessionEvent)

          { ... HttpSession session = httpSessionEvent.getSession(); WindowScopeManager.disposeWindows(session); ... }

          public static void disposeWindows(final HttpSession session) {
          State state = (State)session.getAttribute(WindowScopeManager.class.getName());
          Collection<ScopeMap> scopeMaps = state.windowScopedMaps.values();
          for (final ScopeMap scopeMap : scopeMaps) {
          Collection<Object> windowScopedBeans = scopeMap.values();
          for (final Object windowScopedBean : windowScopedBeans)

          { callPreDestroy(windowScopedBean); }

          }
          }

          However, currently the @PreDestroy on an abandoned window scoped bean gets invoked twice: ICE-7055

          Show
          Jack Van Ooststroom added a comment - The @PostConstruct and @PreDestroy annotation support on CustomScoped beans already seemed to be partially supported. Though I haven't looked into the JSF source code, I suspect the following two calls in WindowScopeManager to help out with the current support of this: facesContext.getApplication().publishEvent(facesContext, PostConstructCustomScopeEvent.class, context); facesContext.getApplication().publishEvent(facesContext, PreDestroyCustomScopeEvent.class, context); These calls and the locations in the code where these calls are made seem to explain the 2 working scenarios: Whenever a window scoped bean is created the @PostConstruct on this window scoped bean gets invoked Whenever a window scoped bean is abandoned but the session hasn't expired yet, the @PreDestroy on this window scoped bean gets invoked The one missing case seem to be the invocation of @PreDestroy upon session expiry for all remaining window scoped beans in the session. However, upon session expiry you're not guaranteed to have a FacesContext. Therefore the similar mechanism cannot be used. Instead, the SessionExpiredListener now invokes the newly created WindowScopeManager.disposeWindows(HttpSession) upon session expiry: public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { ... HttpSession session = httpSessionEvent.getSession(); WindowScopeManager.disposeWindows(session); ... } public static void disposeWindows(final HttpSession session) { State state = (State)session.getAttribute(WindowScopeManager.class.getName()); Collection<ScopeMap> scopeMaps = state.windowScopedMaps.values(); for (final ScopeMap scopeMap : scopeMaps) { Collection<Object> windowScopedBeans = scopeMap.values(); for (final Object windowScopedBean : windowScopedBeans) { callPreDestroy(windowScopedBean); } } } However, currently the @PreDestroy on an abandoned window scoped bean gets invoked twice: ICE-7055
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #25054 Tue Jul 19 12:01:45 MDT 2011 jack.van.ooststroom Fixed JIRA ICE-6826 : Add support for @PostConstruct and @PreDestroy annotations for window-scoped beans; added try-catch block around the windows disposal as a safety net
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/application/SessionExpiredListener.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #25059 Thu Jul 21 07:53:08 MDT 2011 jack.van.ooststroom Fixed JIRA ICE-6826 : Add support for @PostConstruct and @PreDestroy annotations for window-scoped beans
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/application/WindowScopeManager.java
          Hide
          Jack Van Ooststroom added a comment -

          Upon session expiry all window scoped beans contained in the windowScopedMaps and disposedWindowScopedMaps collections will have their @PreDestroy annotated method invoked. Marking this one as FIXED.

          Show
          Jack Van Ooststroom added a comment - Upon session expiry all window scoped beans contained in the windowScopedMaps and disposedWindowScopedMaps collections will have their @PreDestroy annotated method invoked. Marking this one as FIXED.
          Jack Van Ooststroom made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #25062 Thu Jul 21 12:16:32 MDT 2011 jack.van.ooststroom Fixed JIRA ICE-6826 : Add support for @PostConstruct and @PreDestroy annotations for window-scoped beans; don't bail on the first fail
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/application/WindowScopeManager.java
          Ken Fyten made changes -
          Fix Version/s 2.1-Beta [ 10291 ]
          Ken Fyten made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Jack Van Ooststroom
              Reporter:
              Jack Van Ooststroom
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: