【发布时间】:2015-05-05 15:34:56
【问题描述】:
我正在使用 MyFaces Apache 2.0.3 JSF,WAS 8.0.0.10
目前我正在尝试在 OmniFaces 的库提供的 JSF 2.0 中注入 @ViewScope cdi bean @ViewScope。但我收到一个错误:
WebBeans context with scope type annotation @ViewScoped does not exist within current thread。
当我尝试注入 @SessionScope cdi bean 时,一切正常。
我的 JAX-RS 资源的代码:
@RequestScoped
@Path("/events")
public class CalendarResource implements Serializable {
@Inject
private CalendarBean calendarBean;
@Inject
private PropertiesBean propertiesBean;
@GET
@Produces("text/plain; charset=utf-8")
public Response getEvents(@QueryParam("calendarId") String calendarId,
@QueryParam("start") String start,
@QueryParam("end") String end,
@Context SecurityContext securityContext,
@Context HttpServletRequest req
) {
FullCalendar selectedCalendar = calendarBean.getFullCalendar();
System.out.println(calendarId + " " + start + " " + end + " " + propertiesBean.getUser().getName());
return null;
}
我的 CDI bean 的代码:
@Named
@ViewScoped
public class CalendarBean implements Serializable {
@EJB
private CalendarEJB calendarEJB;
@Inject
private PropertiesBean propertiesBean;
@PostConstruct
public void init(){
...
}
...
}
我做错了什么?只要我知道,我可以在狭窄的范围内注入更广泛的范围。谢谢。
更新:当我将@ViewScope 更改为@SessionScoped 时,一切都开始工作了。 OmniFaces 可能有问题吗?
【问题讨论】:
标签: jsf jsf-2 jax-rs cdi omnifaces