Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8131053

JavaFX Scene Router aka Super-Controller


    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u45
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:


      JavaFX provides support for the MVC design pattern, so it makes it rather easy to have one Window split up into View (Stage + Scene), Controller, and Model (POJO), where the controller decides what to do within that window in case particular events do happen. This is fine for single-scene applications, but starting with multiple scenes problems occur.

      If for example a key press in Scene 1 shall show up Scene 2, it might be a design choice to EITHER switch Stage 1 from Scene 1 to Scene 2, OR open a second stage for Scene 2 while Stage 1 continuous to show Stage 2. This choice cannot get decided by neither the controller of Scene 1 nor the controller of Scene 2, and from the SoC principle it is not a good idea to have one shared controller for both scenes.

      What is needed is a central "Super-Controller" for all inter-scene decisions, which is unique to the Application instance in contrast to the existing controllers which one decide intra-scene questions. A typical term for such a "Super-Controller" is Router, and its sole job is to route between Scene instances.

      Unfortunately JavaFX does not have a direct support for Routers, so all application vendors have to provide their own implementation, which is tedious and error prone. Moreover some operating systems already support limited ways of routing natively, like Windows (using registered window templates) and Android (using Intents) which is hard to support correctly once each application invents its own Router.

      Hence it would be a good thing to have a common API for Router which might either wrap around OS-serviced routing, and / or providing a Java-implemented default implementation. That way, an application could be designed as a set of standalone, unrelated scenes (Scene + Controller + Model), which simply callback into the Router in case particular events occure (like closing a Scene, or pressing a particular key, or double clicking a list entry, etc.). It is up to the Controller to forward the intent to the Router, and the Router will decide wether to chage Scene within Stage, to open a new Stage, or even to terminate Application instance.




            • Assignee:
              mkarg Markus Karg
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: