CDI and Navigator API - tutorial?


I’m looking to move from JSF to Vaadin but would like some guidance on using the Navigator API with CDI as ultimately the project I’m working on will have a mobile implementation so bookmarkable views, etc would be handy. The Book of Vaadin mentions a tutorial on this subject but I can’t find anything - I guess it’s not out yet? Other posts on the subject suggest not to bother with Navigator unless your project is “complex” which is a little too subjective for my taste - if things go well, it certainly will end up complex and I’d rather not spend too much time refactoring if I can avoid it! Ultimately CDI is more important to me from an archectural standpoint - Navigator just seems a tidier way of letting the user move around the app and fits more with what I’ve been used to with JSF.

One of the other articles I read said that they didn’t think injecting UI components was a good idea - I’m guessing they mean components such as buttons rather than the Views themselves (even though these are actually components)?

If anyone has good resouces (or a good explanation) on this subject, please point me in the right direction!


I have used CDI ( components and views ) in a few projects now , it works really well, even on a large application ( 100+ views, 700+ classes related purly to the webapp ).

Look at the CDI-MVP and CDI-Proporties addons they have a demo app to explain usage.

It does not however include the Vaadin Navigation api in that demo(last time I checked). I have however integrated this in our applications and it is not hard. Let me know if you still need some info on that and I’ll try and add a tutorial that demonstrate its usage…

Hi Petrus

Thanks for the pointers. I have indeed been using the CDI-MVP demo app to learn about implementing CDI in a Vaadin application and think I’ve figured out how to use the Navigator API with it. However, I’m having a bit of difficulty figuring out the best way of building the application framework and don’t know how best to proceed. Could you advise? Ideas so far:

  • As per the Dashboard demo, UI class handles presenting login page (which would not be injected) and once authenticated, builds the “frame” consisting of menubar and notifications. Navigator remains localised to the UI and is never accessed by any of the View classes - a CDIViewProvider would be used to inject View instances into the UI.
  • UI class instantiates Navigator but doesn’t construct any of the UI apart from a base layout. Control passed to a loginview and following authentication, to the “root” view that builds the frame and handles navigation. To stick with CDI principles I’d need to create a @Provides getter method within the UI class to enable Presenter classes to access the Navigator instance instantiated by the UI. This does seems like an unnecessary abstraction/layer of complexity though.

I think a lot of my uncertainty revolves around whether UI components should be injected rather than instantiated as the whole loose coupling argument seems less relevant than it does with EJBs, etc. What do you think?

Many thanks