3 Replies Latest reply on Oct 26, 2010 6:52 AM by cash1981

    Whats the point with Session scope on Unwrap

    cash1981

      Hi.


      Consider this example




      @Scope(ScopeType.SESSION)
      @Name("test")
      @BypassInterceptors
      public Class Test {
      
          @Unwrap
          public List<String> test() {
            //do a long and major calculation and return the List
          }
      }





      Then you have a view and you are getting your list



      <h:selectOneMenu value="#{someBean.text}">
          <s:selectItems value="#{test}"/>
      </h:selectOneMenu>



      Now in my opinion, because I have Scope session, the list should be cached, or the component at least, however, so that it will run once, but then when you revisit the page in the same session, ut should not run again, but when I re-enter the page the Unwrap method is yet again run.
      So my question is: What is the difference between Session scope and say Event scope here?


      To circumvent this I have manually cached the list in the session context in the @Create method and return the list.

        • 1. Re: Whats the point with Session scope on Unwrap
          cash1981

          Shervin Asgari wrote on Oct 26, 2010 04:47:


          To circumvent this I have manually cached the list in the session context in the @Create method and return the list.


          What I meant to say is that I check the session context in the unwrap method, not @Create

          • 2. Re: Whats the point with Session scope on Unwrap
            lvdberg

            Hi,


            It can event get uglier when you have a ajax-poll on your page. The unwrap is called over and over again. I think this is a JSF-problem which can't be solvd easily. I'm using a two layer approach where the unwrap is used to get things (from the DB or cahche) and a factory to provide them to the visual layer. Its called the same ridiculous number of times, but it's more efficient/faster.


            Leo

            • 3. Re: Whats the point with Session scope on Unwrap
              cash1981

              I asked on irc, and it seems I had misunderstood the Unwrap.


              It seems like Unwrap is used to when it is useful if you want to perform an action before the object is accessed. e.g. the SMPC uses @Unwrap to make sure it has joined the transaction every time.


              Seems like it is Factory that suits my needs, which outjects the result to the specified scope