2 Replies Latest reply on Mar 7, 2007 9:42 AM by Uwe Schäfer

    @In with primitives

    Uwe Schäfer Newbie


      My Task is to keep a few Parameters of a Conversational Bean as defaults in the Session scope.

      My first try is:

      @In(required = false, scope = ScopeType.SESSION)
      @Out(scope = ScopeType.SESSION)
      private int documentListPageSize=0;

      which gives me an exception in
      sun.reflect.UnsafeIntegerFieldAccessorImpl.set due to trying to set an int to null.

      My question is: why does seem try to inject this at all, where the corresponding Object in the Session Scope cannot be found ?

      To work around this, i tried to add a @Factory method returning some default. Did´t help at all.

      What is the best practice for this usage pattern ?

      (I´m using 1.1.7 on JBossAS 4.0.5)

      Thanks, Uwe

        • 1. Re: @In with primitives
          Shane Bryzak Master

          Best practice I'd say is to use an Integer.

          • 2. Re: @In with primitives
            Uwe Schäfer Newbie


            "shane.bryzak@jboss.com" wrote:
            Best practice I'd say is to use an Integer.

            Hi Shane, thanks for your time.

            While it obviously is a good idea to switch to Integer where null-references are wanted, the fact that i used an int initially is a good indicator, that null isn´t that useful ;)
            I do not see, what is wrong with using primitives here. The problem was that the initialization must be done via Seam like this:

            @Out(scope = ScopeType.SESSION)
            private int documentListPageSize;

            @Factory(value = "documentListPageSize", scope = ScopeType.SESSION)
            public int createDocumentListPageSize()
            return UIListHelper.DEFAULT_PAGE_SIZE;

            The problem was that create=true was missing on @In.

            While this works fine now (yep, with *int*s), it looks like doing this programmatically is quite more readable, than the above use of Annotations:

            private SeamSessionLocal pageSize = new SeamSessionLocal("documentListPageSize",

            where SeamSessionLocal is a wrapper to an Attribute of the SessionContext.

            Well kind of flavour, i guess.

            Thanks again Shane.