@FXMLViewFlowContext is null

73 views
Skip to first unread message

Sakit Atakishiyev

unread,
Nov 13, 2016, 3:13:08 AM11/13/16
to DataFX
Hi everyone, I want to create a JavaFX Application fro my client. I found DataFX framework and like it. But I have problem with @FXMLViewFlowContext becuse it returns null each time when I call child fview from my parent. I used lib version 8.0.7 and below codes

1. I create side view in my main controller with i18n resource:
// side controller will add links to the content flow
Flow sideMenuFlow = new Flow(SideMenuController.class);
sideMenuFlowHandler
= new FlowHandler(sideMenuFlow, context, Common.getViewConfiguration());
drawer
.setSidePane(sideMenuFlowHandler.start(new AnimatedFlowContainer(Duration.millis(320), ContainerAnimations.SWIPE_LEFT)));


2. and this my side pane controller
@FXMLController(value = "/res/fxml/test.fxml")
public class SideMenuController {
   
@FXMLViewFlowContext
   
private ViewFlowContext context;


   
@FXML
   
private JFXListView test;


   
@FXML
   
@ActionTrigger("suppliers")
   
private JFXButton suppliers;


   
@FXML
   
@ActionTrigger("history")
   
private JFXButton history;


   
@FXML
   
@ActionTrigger("barcode")
   
private JFXButton barcode;


   
@FXML
   
@ActionTrigger("settings")
   
private JFXButton settings;


   
@FXML
   
@ActionTrigger("report")
   
private JFXButton report;


   
@FXML
   
@ActionTrigger("users")
   
private JFXButton users;


   
@FXML
   
@ActionTrigger("inventory")
   
private JFXButton inventory;


   
@FXML
   
@ActionTrigger("shops")
   
private JFXButton shops;


   
@FXML
   
@ActionTrigger("calculation")
   
private JFXButton calculation;


   
@PostConstruct
   
public void initialize(){
        test
.propagateMouseEventsToParent();
       
System.out.println(context);


       
FlowHandler contentFlowHandler = (FlowHandler) context.getRegisteredObject("ContentFlowHandler");
       
Flow contentFlow = (Flow) context.getRegisteredObject("ContentFlow");
        bindNodeToController
(suppliers, SuppliersController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(inventory, InventoryController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(users, UsersController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(history, HistoryController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(shops, ShopsController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(report, ReportController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(barcode, BarcodeController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(calculation, CalculationController.class, contentFlow, contentFlowHandler);
        bindNodeToController
(settings, SettingsController.class, contentFlow, contentFlowHandler);
   
}


   
private void bindNodeToController(Node node, Class<?> controllerClass, Flow flow, FlowHandler flowHandler) {
        flow
.withGlobalLink(node.getId(), controllerClass);
        node
.setOnMouseClicked((e) -> {
           
try {
                flowHandler
.handle(node.getId());
           
} catch (Exception e1) {
                e1
.printStackTrace();
           
}
       
});
   
}
}
When i run my program i got null pointer exception because of context never injected. I searched but did not find any solution. Also I try old libraries but does not help. 

Sakit Atakishiyev

unread,
Nov 13, 2016, 7:50:35 AM11/13/16
to DataFX
Finally I solved my problem. There are two reasons for this problem. 1. The first one is related to DataFX library version. 2. The second problem is initialize mehtod. When DataFX is start to create controller class instance initialize method will be called by javafx FXMLLoader.load() method and this happen before init ViewFlowContext so that I got NullPointerException. In other word if you use @PostConstruct annotation and call your method with name initialize, like me, your method will be called two times one is when new controller class instance created(context has not init yet) and other one is when @PostConstruct method will be invoked(context has created). This correct for DataFX flow lib 8.0b8 version. I checked this version lib 8.0.7 but I get NullPointerException again. So that I changed my lib version and now everything is ok

Brent King

unread,
Nov 15, 2016, 4:08:11 AM11/15/16
to DataFX
Hi,


From what I remember, 8.0.7 is an old version that was given the wrong number, by mistake. 

8.0.1 works fine for me.
Reply all
Reply to author
Forward
0 new messages