tags:

views:

14

answers:

2

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 Seam manager component at least, so that it will run once, but then when you revisit the page in the same session, it 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 and retrieve it from the context if it is present in the @Unwrap method

+2  A: 

Seems like I have misunderstood the Manager component.

The @Unwrap 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.

It is actually the @Factory annotation that suits my needs, which will outject the return value.

Thus the scope of the component is still valid as normal Seam component scopes. Of course in that exact example, its not that useful as there are no fields.

Shervin
+2  A: 

@Unwrap differs from @Factory because it is evaluated each time it is requested. If you have a page which needs current time and this page request the current date three times as follows

#{currentDate}

#{currentDate}

#{currentDate}

Because the component which encapsulates currentDate defines an @Unwrap method, it is evaluated three times

If you have @Factory instead, it is just evaluated once

#{compon.someFactory}

#{compon.someFactory}

#{compon.someFactory}
Arthur Ronald F D Garcia
Yes, I finally understood that. It's strange, I have been using Seam now daily for 2,5 years, and I still learn stuff. Major framework!
Shervin