4

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

Thanks

Basit
  • 7,824
  • 41
  • 106
  • 185

2 Answers2

10

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

Matt Handy
  • 29,195
  • 2
  • 84
  • 106
  • You mean to say i use @managedBean instead of @named if i want view scope. And in @managedBean i can use CDI scopes. Like for example `@ManagedBean(name = "businessAddUpdate")->@ViewScoped ->@conversationScope-> public class.....` . **-> means next line** Is it? – Basit Mar 06 '12 at 09:58
  • Don't mix both in the annotations of the same class. Either one or the other. Also be careful to import the correct classes. – Matt Handy Mar 06 '12 at 10:15
  • 1
    HHmm now i understood. You mean to say if i want view scope then i use `@ManagedBean(JSf)`but if i want request or session or conversation scope, then i use `@Named(CDI)`. Because bean can have be only in one scope at a time. Is it? – Basit Mar 06 '12 at 10:19
  • 2
    Apache MyFaces CODI provides a CDI adapter for the ViewScope. – Dar Whi Jul 10 '12 at 23:23
0

simply just put seam3 faces module in your classpath or use @ViewAccessScpoed annotation of myfaces CODI.

Mehdi
  • 4,418
  • 4
  • 27
  • 29
  • 1
    CODI has the better @ViewScoped adapter which also handles edge cases. AFAIK that's also the one used in DeltaSpike. – Dar Whi Oct 28 '12 at 20:29
  • @Dar, yes you are right, and jsf module for DeltaSpike is under heavy development and it will be a great module because CODI and seam developers are doing that together ;) – Mehdi Oct 29 '12 at 05:02