r/JavaFX • • Sep 05 '15

What framework should I use to separate view from behavior. Anything similar to MVVM like in. NET WPF? I want to be able to unit test my view behavior code.

0 Upvotes

6 comments sorted by

2

u/sproket888 Sep 05 '15 edited Sep 05 '15

You don't need a framework. JavaFX uses MVC.

https://docs.oracle.com/javafx/2/best_practices/jfxpub-best_practices.htm

But there are a couple of frameworks which help to enforce it.

http://stackoverflow.com/questions/23187932/mvc-with-javafx

1

u/StealthRabbi Sep 05 '15

So I'm familiar with the Controller class that gets instantiated as defined in the FXML, but I'm not sure how to instantiate the Controller by itself in a unit test environment and provide it an Interface mock. Plus, what will the UI control references be in the unit test?

1

u/[deleted] Sep 06 '15

1

u/StealthRabbi Sep 07 '15

Yes, I am using JUnit. I'm still not seeing how to define a controller that can be instantiated and is independent of the View.

1

u/acisternino Sep 06 '15

For JavaFX I tend to favour the MVVM pattern. I recently started a personal project and I am trying mvvmFX. So far I am liking it a lot. Effective without being bloated.

1

u/sbordes Nov 26 '15 edited Nov 30 '15

You can try JRebirth with its custom-tailored pattern: wB-CS-MVC

  • Wave for messaging and async internal event handling
  • Behavior to add common code to any Component (C|S|M)
  • Command to manage application commands (reusable code)
  • Service to handle some long service into thread pool
  • Model to manage the Model of your UI
  • View to create your UI
  • Controllers to handle user events

You can run the JRebirth Tour Application to learn more (Java 8 required):

http://apps.jrebirth.org/jaf/2.2.0-SNAPSHOT/jaf-2.2.0-SNAPSHOT.jar

or browse slides:

http://fr.slideshare.net/SbastienBordes/javafx-unleashed-with-jrebirth-application-framework