7 Replies Latest reply on Aug 20, 2009 10:43 AM by Arno Mittelbach

    Intercept invocation of component's own method

    Tilman Rossmy Newbie

      I would like every invocation of a method of my component to be intercepted, even the ones that the component invokes on itself. Consider something like this:




      @Name("myComponent")
      @LogAllDoSomethings
      public class MyComponent
      {
      
         public void doSomething1()
         {
            doSomething2(); 
         }
      
         public void doSomething2()
         {
      
         }
      }



      Then the @LogAllDoSomethings should output:



      starting doSomething1


      starting doSomething2


      finished doSomething2


      finished doSomething1


      with spring AOP I could achieve this like this:


      @Name("myComponent")
      @LogAllDoSomethings
      public class MyComponent
      {
      
          public void doSomething1()
          {
              ELContext elContext = FacesContext.getCurrentInstance().getELContext();
              ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
              MethodExpression expression = factory.createMethodExpression(elContext, "#{myComponent.doSomething2}", null, new Class[0]);
              expression.invoke(elContext, null);
          }
      
          public void doSomething2()
          {
      
          }
      }



      This approach does not seem to work with seam. Any ideas?