I have an application with 2 Views and 2 Presenters. I have a fixed top menu with a search box using a SuggestionBox. I get the suggestion list from database, and I load it into the MultiWordSuggestOracle of the SuggestionBox, using addAll(..) method.
I'm using UiBinder, and it is my code:
@UiField (provided=true) SuggestBox searchEntriesSuggestBox;
MultiWordSuggestOracle oracle;
public MenuBar() {
oracle = new MultiWordSuggestOracle();
searchEntriesSuggestBox = new SuggestBox(oracle);
initWidget(uiBinder.createAndBindUi(this));
}
public void loadUserEntries(Collection<String> entries){
oracle.clear();
oracle.addAll(entries);
}
The first time that I run the app, I load the suggestions using loadUserEntries(). The problem is when I change my View (and Presenter), because the SuggestBox load an empty MultiWordSuggestOracle, so I have to load the suggestions again, every time I change my Presenter.
I would like to maintain the suggestions (the MultiWordSuggestOracle) as a global variable during the life of the app, to avoid using the loadUserEntries method.
I tried defining a global variable MultiWordSuggestOracle, and each time that I have to load the Presenter, create a new SuggestBox with my global MultiWordSuggestOracle. But it didn't work.
Any idea?
Thanks.