Hi,
I found the problem :)
Change the Model class to this one:
@FlowScoped
public class DataModel {
private int counter = 0;
public DataModel() {
System.out.println("Constructor");
}
public void print(String from) {
System.out.println(from + ": counter = " + counter++);
}
}
When using the wizard now you will get an output like:
Constructor
Constructor
wizard #1: counter = 0
Constructor
wizard #2: counter = 1
Constructor
wizard #3: counter = 2
Constructor
wizard #4: counter = 3
Constructor
wizard #5: counter = 4
What does this means?
First we can see that the counter will change. This means that all the views will change the same model instance. Otherwise we would see always "counter=0". So even in your example all the controller instances in the flow share the same model instance. I think this is the behavior that you want / need. You can change it to the Application scope if you need a singleton.
In addition we see that the constructor of the model is called each time when the she change the view. The big question is "why?". All the views share one model and so we don't need to create a new instance and as we see in the example, we don't use a new instance.
When having a look at the internal DataFX sources for the injection a javassist.util.proxy.ProxyFactory is used as a wrapper for each object instance. This will be created whenever new data is injected. Javassist creates a new instance internally that is maybe used for the wrapper. At the moment I have no idea how this is working and how this can be changed. This could cause issues when working with static fields and therefore it should be fixed. For the next DataFX version I plan to create a Injection interface with 2 useable implementations: Google Guice or the current one. Maybe this problem will be resolved when using google Guice. I will have a look at it once I will refactore the APIs. I think this isn't a show stopper for you, right?