2016-02-19 43 views
0

我想在我的项目中使用Hibernate。我有绑定到数据库表的类。该表中很少有列与其他表有关系(因为主类中的数据量很大)。一切正常。但我不知道如何正确绑定到TableView。休眠 - TableView绑定

@FXML TableView<ClassExample> ExampleTableView; 
@FXML TableColumn<ClassExample, Integer> tableViewColumnID; 
@FXML TableColumn<ClassExample2, String> tableViewColumnString; 

tableViewColumnID.setCellValueFactory(new PropertyValueFactory<ClassExample,Integer>("idZap")); 
tableViewColumnString.setCellValueFactory(new PropertyValueFactory<ClassExample2, String>("INFO")); 

对于第一列,一切正常。但是如何绑定ClassExample2.getINFO(Column“INFO”),它是ClassExample的一部分?

我已经试过这和它的作品 - 但我能做到这一点wthout拉姆达?:

tableViewColumnString.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getClassExample2().getINFO())); 

回答

1

您不能使用PropertyValueFactory访问“属性的财产”,所以你必须提供自己的以某种方式实施Callback<CellDataFeatures<ClassExample>, ObservableValue<String>>。没有要求使用lambda表达式,但它比等效的匿名内部类远没有详细:

tableViewColumnString.setCellValueFactory(new Callback<CellDataFeatures<ClassExample>, ObservableValue<String>>() { 
    @Override 
    public ObservableValue<String> call(CellDataFeatures<ClassExample> cellData) { 
     return new ReadOnlyStringWrapper(cellData.getValue().getClassExample2().getINFO()); 
    }; 
}); 
+0

感谢您的解释。这就是我一直在寻找的:) – Thulion