CDI 缺少 @ViewScoped 和 @FlashScoped
为什么 Java EE 6 CDI 缺少 @ViewScoped 和 @FlashScoped 注释? (尤其是前者让我想知道,因为CDI源于Seam世界,它已经知道非常相似的ScopeType.PAGE...)
使用CDI时推荐的解决方法是什么?使用接缝3?
谢谢
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...)
What are the recommended workarounds when using CDI? Use Seam 3?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@ViewScoped
特定于 MVC 框架 JSF,而不是特定于依赖项注入框架 CDI。只要您与同一个 JSF 视图交互,视图范围就存在。 CDI 并没有真正的“观点”概念。 CDI 的替代方案是@ConversationScoped
的生存时间比请求范围长,但比会话范围短。您只需自己控制终止即可。如果需要,您可以使用 MyFaces CODI 桥接 JSF
@ViewScoped
到 CDI@Named
beans。即将推出的 JSF 2.2 将在javax.faces.view
包中提供与 CDI 兼容的@ViewScoped
。@FlashScoped 确实JSF 中不存在。 JSF flash 范围 基本上存在一个映射它由一个短暂的 cookie 支持,该 cookie 在 HTTP 重定向后仍然存在。您不能让 JSF 将托管 bean 放入此范围内。您必须自己手动将值放入地图中/从地图中获取值和/或使用 EL 中的
#{flash}
引用(它基本上引用了地图)。然而,Seam Faces 却劫持了 JSF 特定的javax.faces.bean
包其@FlashScoped
注释,但这绝对不是来自标准 JSF API。另请参阅:
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 thejavax.faces.view
package.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 specificjavax.faces.bean
package for its@FlashScoped
annotation, but this is definitely not from standard JSF API.See also:
您可以实现上下文并使用 @NormalScope 创建您自己的 CDI 范围,而无需使用任何其他框架或等待新的 JEE7
以获得更深入的解释,我推荐此链接:http://www.verborgh。是/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi/
You can implement the context and use the @NormalScope to create your own CDI Scope witout using any other framework or waiting for the new JEE7
for a more in-depth explanation i recommand this link : http://www.verborgh.be/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi/