I have an issue with a ViewModel. I have this in i...
# tornadofx
b
I have an issue with a ViewModel. I have this in it:
Copy code
var journal = bind(forceObjectProperty = true) { citation?.observable(Citation::journal_id) as Property<Int>? }
    var journalEntry = bind {
            legacyController.journalList?.getElement(journal.value).toProperty()
    }
It is used to feed a combobox, but the problem is even before that I can see it when I do:
Copy code
model.journalEntry.onChange { println("Changed the journal to $it") }
The model is defined as a
Copy code
class CitationModel(var citation: Citation?) : ViewModel() { … }
The model is by default a
Copy code
val model = CitationModel(null)
Once the user loads something, I do a
Copy code
citationView.model.rebind {
                                citation = newCitation
                            }
where newCitation is coming from some database query. I get the right call to rebind, and the object bound is the good one.
If I look at the journalEntry, when it fails, I get:
Copy code
Journal entry post bind ObjectProperty [bean: models.CitationModel@701d8c0f, value: CodeNameEntry(id=, code=, name=)]
where as when it works:
Copy code
Journal entry post bind ObjectProperty [bean: models.CitationModel@701d8c0f, value: CodeNameEntry(id=1112, code=PD, name=PHYTOMEDICINE)]
when changing the model, it always starts working the second time after the object has been changed from null in the model. However the first time, it depends sometimes it works sometimes it doesn't even with the same source data.
I'm not sure I am computing that journalEntry properly so it reflects the changes in journal