vaadin4spring icon indicating copy to clipboard operation
vaadin4spring copied to clipboard

Is it possible to configure Navigator as UIScoped Bean?

Open pesse opened this issue 9 years ago • 4 comments

Hey,

I guess I'm still struggling with the whole Spring IoC mechanic. I was wondering if it is possible to configure a Vaadin Navigator as UIScoped Bean from a specific UI so I am able to Autowire it in my UI/View Components. Has anyone of you experienced guys a hint?

Pesse

pesse avatar Feb 27 '15 10:02 pesse

I'm not 100% sure you can configure it as a UI scope bean, but I think we should figure out a way to make it possible to autowire the current UI's navigator.

peholmst avatar Feb 27 '15 11:02 peholmst

Its possible but causes headaches in Multi-UI environments due to the cyclic dependency between UI and Navigator. This is not a vaadin4spring problem but a bad design decision in core Vaadin.

There are two problems at hand:

  • First the navigator must be initialized together with the UI or at least before it is used but it will register itself with the UI, that means there is no object at all that really needs a navigator dependency at this stage.
  • Second problem is that you'll have to find the correct UI instance to be injected into the constructor of the Navigator class (even though the Navigator does not really use the UI itself but stores it in a private field and just returns it via getter method).

We jumped through some hoops to get this working and the result looks more like a hack than a solution but it seems to work in a single ui environment. The Multi UI support is still work in progress.

StefanPenndorf avatar Feb 27 '15 12:02 StefanPenndorf

Thanks for the replies - so I guess it would be more reasonable to use the EvenBus and some kind of NavigationEvents to have the components losely coupled in a Multi UI environment, right?

pesse avatar Feb 27 '15 13:02 pesse

I'd definitely go for the EventBus and NavigationEvents.

peholmst avatar Mar 01 '15 20:03 peholmst