Dear all,
I started working with the MVP extension from the CDI-Utils addon. This is great stuff.
But I wonder why my view is initialized and my presenter is not. It seems the viewOpened ist never called on the presenter. I have a really easy use case:
@ViewInterface(MainView.class)
public class MainPresenter extends AbstractPresenter<MainView> {
}
public class MainViewImpl extends AbstractView implements MainView { }
// This is where I initialize the app..
@Override
public void attach() {
// i.get();
super.attach();
final MainViewImpl view = mainView.get();
addComponent(view, "content");
view.openView();
}
Now the presenter is not created nor is it initialized. On the log I see only:
INFO: View initialized: interface MainView
INFO: View accessed: interface MainView
When I fire an event from the view, the presenter is initialized.
What I try to do: I would like to initialize the application with some data from the model when the application starts.
What is the recommended way to achieve this?
The primary idea was to set that data either in viewOpened() or initPresenter(), not sure which one is better. I guess viewOpened as the view should be initialized by then. But in the example app its done in initPresenter().
/*
* When the ListPresenter is initialized, it fetches a list of cities from
* backend (personDAO) and passes the list to the view.
*/
@Override
protected final void initPresenter() {
view.setCityOptions(personDAO.listCities());
}
I get this to work by injecting the presenter somewhere and access it via presenter.get() before opening the view. But I think this really is a workaround. Still openView is never called.
I do see there is an MVPExtension class, that tries to register an observer for view opened and opening the view actually fires such an event, but it’s never caught.
Thank you so much