Hello Seb,
as you know, we use our own implementation for creating controllers (FXMLControllerFactory - see below). I implemented a common navigation approach (to support module based application) and create a class, where the current data context (global) can be set (selected order, notification etc.).
If I navigate the first time to the view(s), all is working fine. If I change the module once and come back to the first module views, the data context selection failes with an exception.
I found, that the FXMLModel of FMXLController seams be finalized/destructed (partially) in the meantime, because the call model.sendWave failes internally, because the LocalFacade is null now.
private Wave createWave(final WaveGroup waveGroup, final WaveType waveType, final Class<?> componentClass, final WaveData<?>... waveData) {
final Wave wave = wave()
.waveGroup(waveGroup)
.waveType(waveType)
.fromClass(this.getClass())
.componentClass(componentClass)
.addDatas(waveData);
// Track wave creation
// getLocalFacade is null
getLocalFacade().getGlobalFacade().trackEvent(JRebirthEventType.CREATE_WAVE, this.getClass(), wave.getClass());
return wave;
}
Here an excerpt of data context class:
public class DataContext {
private static OrderHeaderViewTransfer _orderContext;
final public void setOrderContext(final OrderHeaderViewTransfer orderContext, Model sourceModel) {
_orderContext = orderContext;
final WaveData<Object> waveData = Builders.waveData(NmsWaves.DATACONTEXT, new Object());
sourceModel.sendWave(NmsWaves.DATA_CONTEXT_CHANGED, waveData);
}
final public OrderHeaderViewTransfer GetOrderContext() {
return _orderContext;
...
}
Here the call (sample) in controller to set the context (change listener for selecting an element of list)
private class DefaultListChangeListener<Object> implements ChangeListener<OrderHeaderViewTransfer> {
final private Model _model;
final private DataContext _dataContext;
public DefaultListChangeListener(Model model, DataContext dataContext) {
_model = model;
_dataContext = dataContext;
}
@Override
public void changed(ObservableValue<? extends OrderHeaderViewTransfer> observable,
OrderHeaderViewTransfer oldSelection, OrderHeaderViewTransfer newSelection) {
System.err.println(newSelection);
if (oldSelection != null) {
if (orderHeaderService.isDirty(oldSelection.getModelDelegate()))
orderHeaderService.save(oldSelection.getModelDelegate());
}
_dataContext.setOrderContext(newSelection, _model);
}
}
Because of our own FXMLControllerFactory all controllers are singleton instances and the corresponding models should be valid as long as the application is running.
When the models will be disposed? Do you have any idea how I can keep the models valid?
Thanks a lot in advance!
Regards
Andreas