inject is null in eclipse java

42 views
Skip to first unread message

Zakaria Jahoui

unread,
Feb 2, 2017, 10:04:52 AM2/2/17
to DataFX

i start working with datafx, it's a good framework with good feaetures, but not enough documenetion, so here is my problem :

my class Panel_tv:

@FXMLController ("/application/Panel_tableview.fxml")
public class Panel_tv{


@FXML public TableView<Table_view> tb_version;
@FXML public TableColumn<Table_view,String> cl_version;
@FXML public TableColumn<Table_view,Integer> cl_year;

@Inject public Model model;

@PostConstruct
public void init()
{

    System.out.println("2");
    model.to_String();
    ArrayList<Table_view> list = new TableViewHelper().getstyles(model);
    System.out.println(list.size());
    cl_year.setCellValueFactory(new PropertyValueFactory<Table_view,Integer>("year"));
    cl_version.setCellValueFactory(new PropertyValueFactory<Table_view,String>("version"));
    ObservableList<Table_view> data = FXCollections.observableList(list);
    System.out.println(data.size());
    tb_version.setItems(data);

}




his is my class Controller :

 @FXMLController ("/application/Main.fxml")
  public class Controller {

@FXML private Button btn_home,btn_favori,btn_contact;
@ActionTrigger("back")
@FXML private Button btn_logout;
@FXML private Button btn1;
@FXML private VBox vbox_list;
@FXML public TreeView tree_view;
@FXML public Label lbl;
@FXML public StackPane hb_container;
private FlowHandler flowHandler;

@Inject public Model model;


@PostConstruct
public void init()throws FlowException{

    // Picture of buttons 
     Image contact = new Image(getClass().getResourceAsStream("/main/contact.png"));
     Image favori = new Image(getClass().getResourceAsStream("/main/favori.png"));
     Image home = new Image(getClass().getResourceAsStream("/main/home.png"));
     Image logout = new Image(getClass().getResourceAsStream("/main/logout.png"));
     btn_contact.setMaxSize(40, 40);
     btn_favori.setMaxSize(40, 40);
     btn_logout.setMaxSize(40, 40);
     btn_home.setMaxSize(40, 40);
     btn_contact.setGraphic(new ImageView(contact));
     btn_home.setGraphic(new ImageView(home));
     btn_logout.setGraphic(new ImageView(logout));
     btn_favori.setGraphic(new ImageView(favori));
    //URL resource =getClass().getClassLoader().getResource("cars/Ferrari.png");
    //System.out.println(resource);


    TreeViewHelper helper = new TreeViewHelper();
    ArrayList<TreeItem<String>> products = new ArrayList<TreeItem<String>>();
    try {
        products = helper.getmakes();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    tree_view.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    TreeItem<String> rootItem = new TreeItem<String>("Marques");
    rootItem.getChildren().addAll(products);
    tree_view.setRoot(rootItem);
    tree_view.setShowRoot(false);
    }


@ActionMethod("back")
public void btnclick () throws FlowException
{

    TreeItem<String> selectedItem = (TreeItem<String>) tree_view.getSelectionModel().getSelectedItem();
    String s_make = selectedItem.getParent().getValue();
    s_make =s_make.replaceAll("\\s+", "%20");
    System.out.println(s_make);
    String s_model = selectedItem.getValue();
    s_model= s_model.replaceAll("\\s+", "%20");
    System.out.println(s_model);
    Model models = (Model) new parse_object <Model> (Model.class).ParseUri("https://api.edmunds.com/api/vehicle/v2/"+s_make+"/"+s_model+"?state=new&fmt=json&api_key=zk33gaz9xkgnndyp6cupjkmu");
    this.model = new Model();
    this.model.set_md_id(models.get_md_id());
    this.model.set_md_name(models.get_md_name());
    this.model.set_md_nicename(models.get_md_nicename());
    this.model.set_years(models.get_years());
    model.to_String();
    System.out.println("1");
    //PanelNavigator.loadPanel(PanelNavigator.Panel_1);
    Flow innerFlow = new Flow(Panel_tv.class);
    flowHandler = innerFlow.createHandler();
    hb_container.getChildren().add(flowHandler.start(new AnimatedFlowContainer(Duration.millis(320), ContainerAnimations.ZOOM_IN)));
}


i don't know why th inject Model is always null. i know the @POSTCONSTRUCT is executed after all injects are injected.. Did i forget something ??
Message has been deleted

halim

unread,
Oct 29, 2017, 8:00:28 AM10/29/17
to DataFX
salam

you must annotat your class 'Model' by @FlowScoped to allow Flow to create your Model

@FlowScoped
class Model {
....
}

and after you can use it in any controller bu using @Inject annotation
Reply all
Reply to author
Forward
0 new messages