I'm facing a problem when using DI and interceptors in an JSF app.
I have a backing bean that observes JSF events and performs some initial data lookup. In the JSF page the bean is registered as event listener as follows:
<f:event type="preRenderView" listener="#{myBean.loadData}"/>
The bean is pretty forward and looks basically like this:
@Named
@RequestScoped
public class MyBean {
@EJB
private SomeDao dao;
public void loadData() { ... }
public void performSomeStuff() { ... }
}
The dao is properly injected and everything is fine until here. Now I'd like to perform some lazy loading which is done within an interceptor (the particular code doesn't matter as the same behaviour shows up when the interceptor just proceed on the invocation context). So, before calling performSomeStuff() I'd like to ensure that all data is loaded:
@Interceptors(MyInterceptor.class)
public void performSomeStuff() { ... }
At this point the EJB doesn't get injected any longer (NPE s开发者_如何学JAVAhows up...) - any ideas on this?
Settings:
- GlassFish 3.0.1
- WELD-000900 1.0.1 (SP3)
- Mojarra 2.0.2 (FCS b10)
Thanks in advance!
Regards, Alex
If you wanted to make progress, you might try using 299-based interceptors tied in with an interceptor binding as opposed to the EJB-style. If there's a bug in the area, having your interceptor run a bit later might provide some relief.
精彩评论