sialcasa / mvvmFX

an Application Framework for implementing the MVVM Pattern with JavaFX
Apache License 2.0
484 stars 105 forks source link

How to use ViewModel when Model has JavaFX properties? #584

Closed PavelTurk closed 5 years ago

PavelTurk commented 5 years ago

Here it is said that we have 2 options to implement MVVM with JavaFX - it depends whether we want to use JavaFX-Properties in our model or not.

As I understand if my model doesn't have javafx properties then I add fx properties to ViewModel. However, I can't understand what I should do if my model has fx properties. What should I do this case? Something like this:

class ViewModel {
    private ObjectProperty<Person> personProperty = new SimpleObjectProperty<>();
   ...
   personProperty.set(person);
}

or I should duplicate all the properties of the Person in ViewModel and bind every ViewModel property to Person properties, to get View -><- ViewModel -><- Model? Is there any example when model has properties? Please, help.

Note: this question was also asked at StackOverflow

PavelTurk commented 5 years ago

The answer was given at SO