2

I see everybody using MyFaces CODI or SeamFaces ViewScope Services saying that CDI don't have @ViewScope annotation

If the ViewScope serve just to retrieve the bean after each ajax call back, I think CDI provides extension to add your own implementation and fires AfterBeanDiscovery event which will be benefit to retrieve owr bean from ViewRoot Map.

See this topic http://www.verborgh.be/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi/ for more explanation.

So can anyone tell me what's the difference between this implementation and MyFaces CODI or SeamFaces ViewScope ?

Thanx in advance.

Kurohige
  • 333
  • 2
  • 10

1 Answers1

3

The Seam Faces view scope is a little different, in that it behaves just like the JSF view scope but allows CDI injection as well. Also, these are prebuilt solutions vs needing to build your own solution.

John Ament
  • 11,595
  • 1
  • 36
  • 45
  • 1
    in my case I was just in a need of getting my bean after each ajax call back (works perfect with CDI extension but it was really a new created scope for each ajax call) .. I've never used managed bean ViewScope, what is its behavior ? – Kurohige Apr 29 '13 at 21:52
  • 1
    @Kurohige it will make your bean live while user performs actions in the same view (usually ajax actions). This mean, you don't have to load all your resources on every request i.e. load the data for a `` and perform an ajax request to show a popup for edit/delete a row inside it. – Luiggi Mendoza Apr 30 '13 at 04:26
  • thank you @LuiggiMendoza .. one other question ? is there any problem of memory if I retrive my bean from FacesContext ViewRoot ? – Kurohige Apr 30 '13 at 06:10
  • 1
    @Kurohige it will entirely depend the scope of the variable where you assign the bean i.e. a `@RequestScoped` bean retrieved and assigned to an attribute of a `@SessionScoped` bean yes, it will generate memory leaks. – Luiggi Mendoza Apr 30 '13 at 13:49