1

I have noticed that I can get away with using the @RequestScoped annotation from both @javax.enterprise.context.RequestScoped and @javax.faces.bean.RequestScoped.

In the one scenario the faces version seem to work and in the other the context version.

What I want to know is, which is the preferred / recommended?

I am using PrimeFaces framework and only later in my development realized I could use @ViewScoped in most cases.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Koekiebox
  • 5,305
  • 12
  • 50
  • 86

1 Answers1

4

Although they denote the same scope, they're used with totally different bean types.

The faces version is used for JSF's native beans. Those have been effectively deprecated for JSF 2.2.

The context version is for CDI beans. In JSF 2.2 they are a 100% drop-in replacement for JSF's native beans. In JSF 2.1 they are almost such replacement, except for the fact that the native view scope doesn't work with them (but you can add one from OmniFaces, CODI and a couple of other libs).

Mike Braun
  • 3,676
  • 13
  • 14