MvvmFX

logo

MvvmFX is a framework to build applications based on the design pattern "Model-View-ViewModel" with JavaFX.

The library is released under the terms of the Apache License v2. You can find the source code at github: https://github.com/sialcasa/mvvmFX.

Related Articles:

  • Released mvvmFX 1.1.0

    | tagged as
    Summary:

    Yesterday we released the new version 1.1.0 of mvvmFX. This time we have lots of new features that can make the development of JavaFX applications easier. Some of the new features:

    Commands

    The most interesting new feature are the Commands. With them you can now encapsulate actions in the ViewModel and provide them to the View. Each Command has boolean properties showing if it is running at the moment and if it isExecutable. The latter can for example be used in the View to bind the visibility of a button. With CompositeCommands you can compose many commands so that all sub-commands are executed when the composite command is triggered. See the wiki page for a detailed explanation.

    ModelWrapper

    The second big feature is the ModelWrapper. This class can simplify the mapping between the Model and the ViewModel for CRUD like applications. Instead of duplicating the fields of a model class in the ViewModel you can now use the ModelWrapper that support reloading (copy values from Model to ViewModel), resetting (set ViewModel to default values) and committing (copy values from ViewModel to Model). In the wiki you can see a detailed example.

    Using mvvmFX views as items of ListView

    You can now use the CachedViewModelCellFactory as CellFactory for the javaFX ListView component. This way you can use mvvmFX Views as items of the ListView. See a more detailed description in the wiki: https://github.com/sialcasa/mvvmFX/wiki/ListView-containing-mvvmFX-views.

    Inject ResourceBundle in the ViewModel

    Until now it was only possible to inject the ResourceBundle in the View. But for some use cases it would be useful to have the ResourceBundle available in the ViewModel too. With the new version this is possible via the annotation @InjectResourceBundle. In addition we have added a live cycle method for the ViewModel like it was possible in the View before. We use the same naming conventions for this: If the ViewModel has a method with the signature public void initialize() it will be called by the framework after the injection of the ResourceBundle is done.
    public void MyViewModel implements ViewModel {
        @InjectResourceBundle
        ResourceBundle resourceBundle;
    
        private StringProperty title = new SimpleStringProperty();
    
        public void initialize() {
            title.setValue(resourceBundle.getString("app.title"));
        }
        ...
    }
    

    Utility modules

    Additionally we have introduced two more Maven modules: mvvmfx-utils contains utilities that are not directly related to MVVM but that are more generally useful for JavaFX development. We moved the SizeBindingsBuilder and the ListenerManager from the core module to this new module to improve the cohesion of the core module. mvvmfx-testing-utils contains utils that we used for testing purposes internally for some time. Now these utils are available for the public. The most interesting is the GCVerifier that we are using for testing situations where Garbage Collection is important. See the whole list of changes at github: https://github.com/sialcasa/mvvmFX/releases/tag/mvvmfx-1.1.0
    ...

  • mvvmFX 1.0.0

    | tagged as
    Summary:

    Some days ago we have released the first stable release of our mvvmFX library that helps you to implement the Model-View-ViewModel pattern with JavaFX. The new release can be used with Maven/Gradle:

    <dependency>
            <groupId>de.saxsys</groupId>
            <artifactId>mvvmfx</artifactId>
            <version>1.0.0</version>
    </dependency>
    
    compile 'de.saxsys:mvvmfx:1.0.0'
    
    Additionally Alex and me have written an article for jaxenter.de. This is a german version. An english version of the article will follow next week.
    ...

  • ColorPuzzleFX

    | tagged as
    Summary:

    Again, I have rewritten one of my old games with JavaFX. This time I've created a JavaFX version of my old java swing game ColorPuzzle (yes I know, the name isn't very creative). screenshot of the game The game mechanics are the same: You can switch the color of all fields under your control. Everytime you are switching the active color, all fields in the direct neighbourhood of your own fields with that same color are going under your control from now on. The goal is to bring all fields under your control with the fewest moves. Before you ask: Yes, the game idea is not my invention, there are many games of this type out there and my version is only a clone. I create games only because programming is fun and not to become the best game inventor :-) The code is available on github: https://github.com/lestard/ColorPuzzleFX.

    Grid Component

    While the development of the game I have encapsulated the logic for manipulating and drawing the grid and extracted it into it's own component. This way I was able to reuse the grid logic for other projects like SnakeFX. You can view the code for this grid component on github too (https://github.com/lestard/Grid) but it's not intended for wide usage at the moment as documentation and testing far from production ready. It's more like a playground for me. In another post I will describe the idea behind the grid component in more detail.

    MvvmFX

    Another reason to build the game was to create a simple example for our own UI framework MvvmFX.
    ...

  • MvvmFX article in JavaMagazin

    | tagged as
    Summary:

    In the JavaMagazin 06/2014 there is an article about MvvmFX written by Alex and me. In this article we describe the design pattern Model-View-ViewModel and show how you can apply it to your application with our framework MvvmFX. Additionally we were showing some of the internals of JavaFX and MvvmFX. For example I'm describing how the loading of FXML files is done in JavaFX and how we hook up into this process to enable the usage of Dependency Injection frameworks. Another part of the article is the combination of MvvmFX and SynchronizeFX and how we are using it in our own applications at Saxonia Systems.
    ...

  • MvvmFX

    | tagged as
    Summary:

    Today I like to introduce another open source library that my workmate Alexander Casall an me are creating at Saxonia Systems. Alex had the idea to try out the design pattern "Model-View-ViewModel" that was created by Microsoft engineers for Windows Presentation Foundation (WPF) and XAML and that is also used by some JavaScript frameworks like KnockoutJS. The design pattern uses some technical capabilities of a modern UI technolgy like (bi-directional) data-binding and descriptive UI declaration to simplify the development of the UI and to make testing UI code easier. JavaFX in version 2 supports both of these capabilities: It includes Properties and Data-Bindings and FXML, a xml dialect to create the UI for JavaFX. At the moment our MvvmFX-library is at the very beginnning. We are trying out what is possible and what is not. We would be very pleased if you like to give it a try. You can find it on github: https://github.com/sialcasa/mvvmFX

    The MVVM Design Pattern

    Let's start with the View. With MVVM the view has to be silly. It may not contain any logic but only describe what is visible in the UI. The UI specific logic is developed only in the ViewModel. The viewmodel contains the whole state of the UI and the logic that updates and changes this state. It provides the state to the outside in the form of Properties. The view can now bind itself to the properties of the ViewModel. When the state of the viewmodel changes the view is automatically updated because of the binding. The viewmodel knows the model. How exactly the model is created isn't part of the MVVM pattern. It is the interface to the business logic and the rest of the application. The viewmodel takes the informations that are needed to be presented in the view from the model and brings that informations in the right form in which the view needs them. A common example is a UI that should show the name of a person. The model has Person instances that are containing string variables for "forname" and "surname". In the UI you are expecting this informations to be presented in a nice way. The viewmodel would take the person instance and concatenate the for- and surname to one single string that is provided as a property "name". The view has a label that's textProperty is bound to the name property of the viewModel. The design pattern defines a strict top-down visibility for the components. The View knows the ViewModel. The ViewModel knows the Model but not the View. And the Model knows neither the View nor the ViewModel.

    Testing

    What is really cool about this design pattern is that the whole UI specific logic is only located in the viewmodel. Conditions like "Is the button x disabled or enabled?" are developed in the viewmodel. The view doesn't know about this conditions. It only knows that there is a button and that it's visibility property is bound to a boolean property in the viewmodel. The view doesn't care about under which conditions this boolean property is true or false. This enables you to unit-test your UI logic. The viewmodel is only a simple Java class. You don't need to boot-up the whole application to perform difficult UI integration tests. JUnit is all you need.
    ...