How to use view scope in case of CDI in JSF 2.0

前端 未结 2 1898
时光取名叫无心
时光取名叫无心 2021-01-06 08:38

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 wa

2条回答
  •  鱼传尺愫
    2021-01-06 09:12

    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.

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

    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).

    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).

提交回复
热议问题