Created
September 2, 2014 22:17
-
-
Save brunoborges/1124b1339a966fe3ec58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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