JSF 2.0默认提供的视图范围如下:
@javax.faces.bean.NoneScoped
@javax.faces.bean.RequestScoped
@javax.faces.bean.ViewScoped
@javax.faces.flow.FlowScoped
@javax.faces.bean.SessionScoped
@javax.faces.bean.ApplicationScoped
但是,其中的@javax.faces.bean.ViewScoped,无法与JavaEE CDI一起使用,即一个Java类无法这样定义:
@javax.inject.Named
@javax.faces.bean.ViewScoped
public class AManagedBean {
...
}
所以在JSF 2.0/2.1中,只能如下定义Java类:
@javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
public class AManagedBean {
...
}
为了解决该问题,JSF 2.2提供了额外的javax.faces.view.ViewScoped,以替代javax.faces.bean.ViewScoped(为了向后兼容,同时保留了javax.faces.bean.ViewScoped),从而可以如下定义Java类:
@javax.inject.Named
@javax.faces.view.ViewScoped
public class AManagedBean {
...
}