spring - Dependency Injection too late -
i using javafx 2 in conjunction spring framework, injection happens late. controller instanciated fxml-loader, spring injection fellow member variables of controller works, works late, means in (1) injection yet didn't happen , in (2) injection did happen:
public class maincontroller extends abstractcontroller { @autowired public statusbarcontroller statusbarcontroller; // implementing initializable interface no longer required according // http://docs.oracle.com/javafx/2/fxml_get_started/whats_new2.htm: private void initialize() { borderpane borderpane = (borderpane)getview(); borderpane.setbottom(statusbarcontroller.getview()); // (1) null exception! } // linked button in view public void sayhello() { borderpane borderpane = (borderpane)getview(); borderpane.setbottom(statusbarcontroller.getview()); // (2) works! } }
any way allow spring inject statusbarcontroller
in before state? can't allow user have click button load gui ;-)
my appfactory this:
@configuration public class appfactory { @bean public maincontroller maincontroller() throws ioexception { homecoming (maincontroller) loadcontroller("/main.fxml"); } protected object loadcontroller(string url) throws ioexception { inputstream fxmlstream = null; seek { fxmlstream = getclass().getresourceasstream(url); fxmlloader loader = new fxmlloader(); node view = (node) loader.load(fxmlstream); abstractcontroller controller = (abstractcontroller) loader.getcontroller(); controller.setview(view); homecoming controller; } { if (fxmlstream != null) { fxmlstream.close(); } } } }
you should set controllerfactory on fxmlloader in charge of creating controller instance.
spring dependency-injection javafx-2
No comments:
Post a Comment