I have a shared GWT widget "HeaderView" which is a header for all views. I instantiate it through GIN via -
bind(HeaderView.class).asEagerSingleton();
I can then inject into my views like so -
@Inject
public DashboardViewImpl(HeaderView headerView) {
this.headerView = headerView;
initWidget(dashboardViewUiBinder.createAndBindUi(this));
}
This works fine for the first time a view is displayed. However, if I change places and then go back to a view that has already been displayed once the "HeaderView" is no longer visible. Inspecting the HTML shows that it is no longer attached to the DOM.
My views are bound as singletons -
bind(DashboardView.class).to(DashboardViewImpl.class).in(Singleton.class);
I am assuming that the HeaderView is being removed from the DOM after loading the next page due to widgets only being allowed to have a single parent.
Is there a correct way to share a widget between all views in a GWT application?