1 2 Previous Next 21 Replies Latest reply on Jan 9, 2007 1:07 PM by Eric Ray

    @Out frustration

    Todd Main Newbie

      I can't get @Out to work as I expected. I'm just testing a trivial stateless session bean with a trivial page. I create a bean, outject it, and try to display its attribute on the page.

      The problem is, the bean never makes into the scope that the page is rendered under. If I view "debug.seam", there are no beans in any scope (other than the definitions in the application scope).

      However, if I add "(scope=ScopeType.SESSION)" tothe @Out tag, all is well.

      I tried other scopes like EVENT and PAGE with no success. How do I simply outject a bean to the page that I'm displaying??? I don't want it in SESSION scope, and there's no value in a conversation in this case.

      Here is my code. Let me know if you need my vast array of config files..

      package mypackage;
      import javax.ejb.Local;
      public interface Test {
       public String view();

      package mypackage;
      import javax.ejb.Stateless;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      public class TestAction implements Test {
       private Bean bean;
       public TestAction() {
       public String view() {
       bean = new Bean("I am a bean");
       return "/test.xhtml";

      package mypackage;
      import org.jboss.seam.annotations.Name;
      public class Bean {
       private String name;
       public Bean() {
       public Bean(String name) {
       public String getName() {
       return this.name;
       public void setName(String name) {
       this.name = name;

      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:s="http://jboss.com/products/seam/taglib" xmlns:t="http://myfaces.apache.org/tomahawk"
       xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" prefix="h"
       xmlns:c="http://java.sun.com/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions">
       <h:inputText value="#{bean.name}" />
       <s:link linkStyle="button" action="#{test.view}" value="View" />

        • 1. Re: @Out frustration
          Glenn Newbie

          my guess is that you would have to outject to at least a conversation scope.

          try @Out(scope=ScopeType.CONVERSATION)
          private Bean bean;

          • 2. Re: @Out frustration
            Todd Main Newbie

            That worked perfectly!

            Was it actually defaulting to "STATELESS" scope? I seem to remember that somewhere.

            BTW, what are EVENT and PAGE scope useful for (since they didn't work for me in this example)?

            • 3. Re: @Out frustration
              Jim Hazen Expert

              @Out's scope defaults to the scope of the enclosing controller, in this case the SLSB. SLSB have a stateless scope. I think that Seam may actually promote the outjection of context variables of stateless components to event scope for you (but I'm not positive).

              Event scope is like JSP request scope and page scope is like JSP page scope. My guess is this example didn't work for you because you used navigation in your JSF action. If so, your view came in two requests. The first outjected the Bean, then left scope. Then you made the next request to view the page and saw everthing with their original values.

              I hope this clears up the scoping question.

              • 4. Re: @Out frustration
                Todd Main Newbie

                I didn't knowingly use any navigation. I do have a pages.xml file, but the "test.xhtml" page is not included in it since I was navigating there "directly" by returning "/test.xhtml" from the seam action. Still, as long as I can use CONVERSATION scope and everything works, I'm happy!

                Thanks for the explanations.

                • 5. Re: @Out frustration
                  Todd Main Newbie

                  BTW, Was there something obvious in the manual that I missed that would have cleared this up? It seems like the kind of thing that lots of people would have trouble with (I'm trying not to feel like an idiot). Maybe it's a good candidate for the problems FAQ?

                  • 6. Re: @Out frustration
                    Jim Hazen Expert

                    Well this is kind of core to bijection and contextual components. @Out is a general concept supported by all components over six searchable contexts.

                    Where did you think your object was going? I'm not trying to be mean, rather trying to figure out where any new documentation should go. Is the misunderstanding about contextual components, or about the function of the @Out annotation?

                    • 7. Re: @Out frustration
                      Todd Main Newbie

                      I guess I truly don't understand how contexts really work.

                      In the case of my example, I still don't understand why EVENT and PAGE scope didn't work (when I tried setting the @Out scope). You mentioned something about using navigation, but I'm not clear on how I could change the example above so that the rendered page has access to the EVENT scope.

                      Also, I don't really understand PAGE scope. I would have thought that PAGE scope would work in my case.

                      If I'm using some sort of implicit navigation to reach test.xhtml, how should I be doing it so that the page has access to components that I place in the EVENT or PAGE scope?

                      • 8. Re: @Out frustration
                        Jim Hazen Expert

                        How many pages do you have? You list some xhtml but don't tell where it came from. What is your desired navigation?

                        • 9. Re: @Out frustration
                          Todd Main Newbie

                          Well, this was just a test example. My application has all sorts of the usual cross-page navigation.

                          In the example above, the page navigates to itself. The first time you load it (.../test.seam), there's no "bean" in any context, so it's blank. When you click the button, it goes to the action, which returns back to the same page.

                          It's that last part that confuses me. Since my action returns "/test.xhtml", I was assuming that when the page was rendered, it would see any bean that was placed into the EVENT or PAGE scope. I still don't quite understand what PAGE scope does.

                          Anyway, I realize that Seam does a redirect to display the page, but I thought that the serialized context was passed along to the page somehow. I can't figure out what is happening in between my action exuction and my page rendering that makes an EVENT or PAGE scoped bean inaccessible to the page.

                          • 10. Re: @Out frustration
                            Jim Hazen Expert

                            Well EVENT obviously won't work because state is destroyed at the end of the request, so it won't be available across redirects (which have 2 requests).

                            PAGE on the other hand I'm not 100% sure about. I'll admit I don't use page scope. I was under the impression that this was like a mini-session tied to a given instance of a page. So if you had data that was specific to a single page, yet needed to save state across requests you could use page scope. A clickable list with data that changes due to other events on the back end is given as an example in the documentation. So in your case where you navigate back to the same view, I'd expect page scope to work. If you're sure it doesn't, then either I don't understand what page scope actually does, or there may be a bug in Seam.

                            Page scope in this understanding would seem to leak memory like the session though, as there would be no way to clean up resources of an infrequently used page. In this case, a conversation may still be desirable even though page scope is available. Plus we know it works. :)

                            It may be that I'm wrong and page scope may simply restrict event data to a given view. However if this were the case, I'd think page would be the narrowest context, and yet the docs say that event is.

                            • 11. Re: @Out frustration
                              Todd Main Newbie

                              I'm noticing that some of the Seam examples use EVENT for the scope of Session Beans. Maybe I should be using that instead of @Stateless for my session bean...

                              • 12. Re: @Out frustration
                                Jim Hazen Expert

                                Just curious. What JSF state saving technique are you using? If you change this to client, does page scope work?

                                • 13. Re: @Out frustration
                                  Jim Hazen Expert

                                  Well it just doesn't make sense for a stateless component to outject anything, because it wouldn't go anywhere. *IF* (I'm still not sure) Seam is nice and automatically outjects objects from stateless components into event scope, then the examples were likely written in a time where Seam didn't have this feature. If Seam doesn't have this feature, then scoping your session bean into event scope (making it an EVENT scoped component) saves you from having to explicitly scope your @Out annotation every time.

                                  • 14. Re: @Out frustration
                                    Jim Hazen Expert


                                    "CptnKirk" wrote:
                                    Well it just doesn't make sense for a stateless component to outject anything, because it wouldn't go anywhere.

                                    And this isn't strictly true either. There are a whole class of problems where you want to have a stateless component (like a SearchManager) to outject into another scope (possibly conversation). What I should have said is that it doesn't make any sense to outject into stateless scope.

                                    1 2 Previous Next