Binding nested object properties to TableView in JavaFx


I have the next class

public class ProductStockDto extends 

    private Long id;
    private Long amount;
    private ProductDto product;
    private StockDto stock;

    //getters and setters...

In JavaFx I have my table and I want to bind the property to the column, something like this.

ObservableList<ProductStockDto> data = FXCollections.observableArrayList();
nameColumn.setCellValueFactory(new PropertyValueFactory(""));

But when I do that, the rows on the TableView appears on blank.

Somebody can help me with this? I want to bind nested object properties, on Java Swing was something like that ${}


7/15/2014 10:32:14 PM

This format is not supported in Javafx, as a work around, you can try something like this :

nameColumn.setCellValueFactory(new Callback<CellDataFeatures<ProductStockDto, String>, 
                                                         ObservableValue<String>>() {  
    public ObservableValue<String> call(CellDataFeatures<ProductStockDto, String> data){  
         return data.getValue().getProducts().nameProperty();  

where ProductDto will have

public class ProductDto{

    private StringProperty name = new SimpleStringProperty("Itachi");

    public String getName() {
        return name.get();

    public void setStreet(String name) {;

    public StringProperty nameProperty(){
        return name;
7/16/2014 7:05:13 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow