Java – CDI is missing @ viewscoped and @ flashscoped

Why are the @ viewscoped and @ flashscoped annotations missing from Java EE 6 CDI? (especially the former makes me feel strange, because CDI comes from the seam world, and it already knows a very similar scopetype. Page...)

What is the recommended solution when using CDI? Using seam 3?

thank you

Solution

@Viewscoped is specific to MVC framework JSF, not dependency injection framework CDI As long as you interact with the same JSF view, the view scope will exist CDI has no real concept of "viewpoint" The CDI alternative is @ conversationscoped, which has a longer lifetime than the request scope, but shorter than the session scope You just need to control the termination If necessary, you can bridge JSF @ viewscoped to CDI @ named bean using myfaces Codi The upcoming JSF 2.2 will be available in javax faces. CDI compatible @ viewscoped. Is provided in the view package

@ flashscoped doesn't exist. In JSF JSF flash scope basically has a map supported by a short-lived cookie that survives HTTP redirection You can't let JSF put managed beans in this scope You must manually put / get the values from the map and / or use the #{flash} reference in El, which basically reflects the map However, seam faces has hijacked JSF specific javax. Java for its @ flashscoped annotation faces. Bean package, but this is definitely not from the standard JSF API

You can also see:

>Add items to list in request scoped bean – contains some specific examples of CDI alternatives

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
***
下一篇>>