CDI缺少@ViewScoped和@FlashScoped [英] CDI missing @ViewScoped and @FlashScoped

查看:100
本文介绍了CDI缺少@ViewScoped和@FlashScoped的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Java EE 6 CDI缺少@ViewScoped和@FlashScoped注释? (特别是前者让我想知道,因为CDI源于Seam世界,它已经知道非常相似的ScopeType.PAGE ...)

Why is Java EE 6 CDI missing the @ViewScoped and @FlashScoped annotations? (especially the former makes me wonder, because CDI stems from the Seam world, which already knew the very similar ScopeType.PAGE...)

当推荐的解决方法是什么时候使用CDI?使用Seam 3?

What are the recommended workarounds when using CDI? Use Seam 3?

谢谢

推荐答案

@ViewScoped 特定于MVC框架JSF,而不是依赖注入框架CDI。只要您与相同的JSF视图交互,视图范围就会存在。 CDI并没有真正的观点概念。 CDI的替代方案是 @ConversationScoped ,其持续时间超过请求范围,但短于会话范围。您只需自己控制终止。如有必要,您可以使用 MyFaces CODI 来桥接JSF @ViewScoped 到CDI @Named bean。即将推出的JSF 2.2将在 javax.faces.view 包中与CDI兼容 @ViewScoped

The @ViewScoped is specific to the MVC framework JSF, not to the dependency injection framework CDI. The view scope lives as long as you're interacting with the same JSF view. CDI has not really a notion of "views". The CDI alternative to that is @ConversationScoped which lives longer than the request scope, but shorter than the session scope. You only have to control the termination yourself. You can if necessary use MyFaces CODI to bridge the JSF @ViewScoped to CDI @Named beans. The upcoming JSF 2.2 will have a CDI compatible @ViewScoped in the javax.faces.view package.

@FlashScoped 不存在。 JSF flash范围基本上存在由生存HTTP重定向的短生命cookie支持的映射。你不能让JSF把托管bean放在这个范围内。你必须自己在地图中手动输入/获取值和/或使用EL中的#{flash} 引用,它基本上反映了地图。然而, Seam Faces 已经劫持了JSF特定的 javax.faces.bean @FlashScoped 注释的包,但这绝对不是来自标准的JSF API。

The @FlashScoped doesn't exist in JSF. The JSF flash scope exist of basically a map which is backed by a short-living cookie which survives HTTP redirects. You cannot let JSF put managed beans in this scope. You've to manually put/get the values in/from the map yourself and/or use the #{flash} reference in EL which basically refrences the map. Seam Faces has however hijacked the JSF specific javax.faces.bean package for its @FlashScoped annotation, but this is definitely not from standard JSF API.

  • Add items to List in Request Scoped Bean - contains some concrete examples of CDI alternatives

这篇关于CDI缺少@ViewScoped和@FlashScoped的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆