Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created September 2, 2014 22:17
Show Gist options
  • Save brunoborges/1124b1339a966fe3ec58 to your computer and use it in GitHub Desktop.
Save brunoborges/1124b1339a966fe3ec58 to your computer and use it in GitHub Desktop.
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setControllerFactory(c -> {
Object controller = CDI.current().select(c).get();
// we don't want a proxy. In case bean is @ApplicationScoped
// then we need to extract the real object behind proxy
BeanManager bm = CDI.current().getBeanManager();
Context ctx = bm.getContext(ApplicationScoped.class);
Set<Bean<?>> beans = bm.getBeans(c);
if (!beans.isEmpty()) {
Bean bean = bm.resolve(beans);
controller = ctx.get(bean);
}
return controller;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment