使用Bindings Utility类的selectXXX()方法

时间:2019-05-21 18:29:32

标签: java javafx properties binding

我正在尝试为嵌套属性创建绑定,但发生异常:评估select-binding [dateString]时发生异常

我有一个这样的tableview的表列:

TableColumn<Motorista, String> lastVisitMotoristaC = new TableColumn<>("Última visita");
lastVisitMotoristaC.setCellValueFactory(m -> Bindings.selectString(m.getValue(), "lastVisitO", "dateString"));

Motorista类:

public class Motorista{

    private Visita lastVisit;
    private lastVisitO;

    .
    .
    .

    public Visita getLastVisitO() {
        return lastVisitOProperty().get();
    }

    public ObjectProperty<Visita> lastVisitOProperty() {
        if (lastVisitO == null)
            lastVisitO = new SimpleObjectProperty<>(getLastVisit()); //<- if try new Visit() it works but I want to use 'lastVisit'
        return lastVisitO;
    }

    public void setLastVisitO(Visita lastVisitO) {
        lastVisitOProperty().set(lastVisitO);
    }
}

Visita类:

public Class Visita{

   private dateString;

   .
   .
   .

   public String getDateString() {
        return dateStringProperty().getValue();
    }

    public StringProperty dateStringProperty() {
        if (dateString == null)
            dateString = SimpleStringProperty(...);
        return dateString;
    }

    public void setDateString(String dateString) {
        dateStringProperty().set(dateString);
    }
}

0 个答案:

没有答案