4 Replies Latest reply on Oct 2, 2005 11:37 PM by Gavin King

    Suggest InterceptionType.ALWAYS as default.

    ryan dewell Novice

      I don't know why, but I keep getting caught with problems related to @Intercept(InterceptionType.ALWAYS). I'm just glad I finally figured it out because I've been banging my head against the wall for quite a while now! :)

      More often than not I'm using this on my beans to get them to behave how I expect them to. Specifically, to get them to display properties in the view! It seems really odd to me that injection doesn't occur when beans are evaluated for the view without this annotation present. FYI I'm using facelets.

      Anyway, just a personal experience, and I'd have to give a +1 to making ALWAYS the default. To my thinking, if the bean is requested anywhere, at any phase, I certainly ALWAYS expect it to be injected... And definitely as the view is rendered/evaluated.

      On a semi-related topic.... What if I have one bean at the "top" of the EL evaluation stack set to ALWAYS, and it is injected with beans who are NOT set to ALWAYS... are they injected then since their "parent" is set to ALWAYS? If not, that may be confusing for folks.

      As it stands, I'm going to be setting ALWAYS on all my seam beans just to be safe. Although I'm sure there is a good reason for it, the behavior otherwise just seems too unexpected for my tastes. Why if a bean is being "used" in any fashion whatsoever, view/invoke_application/etc, should it not be injected? Or, what is the reason for not injecting beans as they are requested/used?


        • 1. Re: Suggest InterceptionType.ALWAYS as default.
          Gavin King Master

          Yes, I've decided to make this change (I was concerned about performance, but it's probably not a big deal).

          But I've gotta wonder why you need injection during RENDER_RESPONSE. I never needed this in building the example apps. Are you running database queries while rendering the view?

          The one case I know of for @Intercept(ALWAYS) is a non-facelets request (ie. a HTTP GET instead of POST), and in this case it is always needed.

          But usually, you should be using facelets requests, I suppose. <h:commandLink/> instead of <a href/>. At least that was the impression I always got.

          • 2. Re: Suggest InterceptionType.ALWAYS as default.
            ryan dewell Novice

            That's great to hear. IMHO it will ease the development of Seam applications.

            I'm finding that in my own mileage, I need injection for render_response more often than not. Here are just two examples:

            1) A bean with a boolean getter called: getHasMessages. This just returns true/false if FacesContext contains messages. Thus, it needs to be injected with FacesContext to be useful at all.

            2) A bean with a boolean getter called: getIsAuthenticated. I'm using this in a view to hide some stuff that non authenticated users don't have access to. This bean requires another bean that actually manages the full authentication lifecycle for a User. In short, this example is just about high bean granularity.

            I've got plenty more -- but I'm glad to hear that ALWAYS will become a default. FYI, kudos on Seam. Every once in a while you come across a technology that just "makes sense". Hibernate, EJB3, JSF, and now Seam all come to mind.


            • 3. Re: Suggest InterceptionType.ALWAYS as default.
              ryan dewell Novice

              Hopefully this fits in the current thread. A couple of other things I've finding to be "givens" on my injections:

              @In(...., required=true, create=true)

              This just seems more EJB'ish to me?


              • 4. Re: Suggest InterceptionType.ALWAYS as default.
                Gavin King Master

                required=true is already the default.

                I dont think create=true is a very safe default.