4 Replies Latest reply on Mar 3, 2009 6:36 PM by raoul schmidiger

    Resetting factory object

    John Smith Newbie

      Hello,


      I have a factory method on a stateful bean that by default outjects into the conversation scope.



      private Integer trackCount;
      
      @Factory(value = "trackCount")
      public Integer getTrackCount() {
         trackCount= calculate();
         return trackCount;
      }



      At certain points during the application I wish to refresh/reset the factory value. I tried two ways to achieve this, but surprisingly none seam to work for me:


      1) Call a reset method



      private void resetTrackCount() {
         trackCount = null;
      }
      




      2) Use @Observer



      @Observer("resetCounts")
      @Factory(value = "trackCount")
      public Integer getTrackCount() {
          trackCount= calculate();
          return trackCount;
      }
      
      private void resetTrackCount() {
         Events.instance().raiseEvent("resetCounts");
      }



      The second method would have been very elegant if it had worked! After reseting both ways, the value of trackCount holds it's previous value


      Can anyone see where I'm going wrong or suggest an alternative way of achieving this?


      thanks!