在JSF 2.0中使用CDI时如何使用视图范围 [英] How to use view scope in case of CDI in JSF 2.0

查看:119
本文介绍了在JSF 2.0中使用CDI时如何使用视图范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Netbeans 6.9中创建了一个JSF 2.0项目.我开始使用CDI.创建项目后,当我尝试添加范围时,我注意到其中没有视域.我想知道对话范围和视图范围是指相同的东西吗?我可以使用对话范围代替视图范围吗?如果没有,那么我该如何在CDI中使用视图范围.我也知道接缝是解决方案,但是我如何在netbeans中使用接缝.是否有用于缝制的netbeans插件? seam-3

I created a JSF 2.0 project in Netbeans 6.9. I am starting using CDI. After creating project when i tried to add scope, then i noticed that there is no viewscope in it. I want to know that are the conversation scope and view scope refer to same things? Can i use conversation scope in place of view scope. If no then how can i use view scope with CDI. I also came to know that seam is the solution, but how can i use seam with netbeans. Is there any netbeans plugin for seam? seam-3

谢谢

推荐答案

CDI没有视图范围.对话范围是不一样的.只要您使用同一个视图,视图范围的Bean就可以存在,并且可以在页面的部分或全部重载下存活.

There is no view scope for CDI. The conversation scope is not the same. A view scoped bean lives as long as you work with the same view and survives partial or full reloads of the page.

如果要使用CDI的对话范围,则您的应用程序必须设置对话的开始和结束.

If you want to use CDI's conversation scope, your application has to set the beginning and end of the conversation.

根据我的经验,您可以将CDI范围与JSF的视图范围一起使用(例如,将CDI范围用于会话和应用程序Bean,并在需要的地方使用JSF视图范围).

From my experience you can use CDI scopes together with JSF's view scope (e.g. use CDI scopes for session and application beans and JSF view scope where you need it).

更新: 但是,您不能将Managad bean注入CDI bean.反之亦然.这是更常见的情况(从更广泛的范围注入到更窄的范围).

UPDATE: However, you can't inject a managad bean into a CDI bean. The other way around works. And that is the more common case (injecting from a broader scope into the narrower).

这篇关于在JSF 2.0中使用CDI时如何使用视图范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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