4 Replies Latest reply on Aug 27, 2009 1:38 PM by israel.bgf

    Implementing an @OnViewLoad

    israel.bgf

      I want to implement an annotation that executes an method at the first time the view is rendered, but not on it's subsequently post-backs. The behavior is exactly the same of the @Create annotation in a Page scoped component, it only get executed once while your are in the page, but i want something to reproduce this behavior to other scopes.


      I want to use the interceptor functionality of the Seam Framework, but I'm a bit lost. Any ideas?

        • 1. Re: Implementing an @OnViewLoad
          israel.bgf

          The final thing should be something like this:



          @Scope(ScopeType.SESSION)
          public class Bean{


          @OnViewLoad
          public void onLoad(){
          System.out.println(this is only executed once per view acess);
          System.out.println(Postbabacks do not trigger this method);
          }


          }


          The problem is: i dont know how to say to seam: Hey framework, always that something is executed in a class check for an @OnViewLoad, if you find it try this method:


          if(/blabla.isPostback?/){
          //execute the method
          } else {
          //ignore it and keep going
          }


          Got it?


          Thanks in advance,

          • 2. Re: Implementing an @OnViewLoad
            cash1981

            Why cant you just create a normal conversation scoped component with a @Create method, and then you can execute that on pages.xml with execute action. The difference between a page scoped component and an conversation (not long running conversation) is a conversation also lives through a redirect.


            This should solve your problem. Yes its a workaround, but it should work.

            • 3. Re: Implementing an @OnViewLoad
              swd847

              You want to add a default interceptor that does this check. This is a pain at the moment as you have to list all the default interceptors plus your new one in the


              <core:init> 
              



              tag.

              • 4. Re: Implementing an @OnViewLoad
                israel.bgf

                How exactly is the syntax to achieve this Stuart? And Shervin, you are right there are some other ways to achieve that, but at the moment i'm trying to see custom annotations in action, :)