-
1. Re: Default CDI injections
rhanus Feb 28, 2013 7:40 AM (in response to elsebbo)I would use an application scoped bean with session scoped producer and a default producer
btw it's not good idea to mix jsf managed beans with cdi see this great article for more details
-
2. Re: Default CDI injections
elsebbo Feb 28, 2013 8:23 AM (in response to rhanus)Thanks for this link! Interesting information indeed.
Meanwhile I managed to create some workaround, which works pretty well for my purpose:
I designed some factory for users, which is application scoped and keeps track of all logged in users. (@WebUser in my case). The business logic uses @CurrentUser for different actions. So the code of my factory looks like the following:
@ApplicationScoped
public class UserFactory {
@Inject @WebUser Instance<UserBean> wu;
@Produces @CurrentUser String getCurrentUser() {
try {
return (wu.get() != null)?wu.get().getUserId():"system";
} catch (Exception ex) {
return "system";
}
}
}
The main problem was the injection of the @WebUser objects. If you use @Inject @WebUser UserBean instead of this workaround, the application will keep crashing due to the cursed ContextNotActiveException.