I am quite new to Vaadin Flow, after programming a Web Frontend with FrameWork 8.
So I excuse in advance if my question may be very silly.
I implemented a Login/Signup View. Now I would like to instantianate here my ApplicationContext class to give e.g. the jOOQ DSLContext and information about the logged in user’s authentication category to the main view route. How can I access the instance of my MainView class to set its ApplicationContext?
Thank you very much in advance, Elke
Hi Elke,
Are you using Spring or another framework for dependency management? If so, you should be able to @Autowire your components.
If you are not using Spring or similar framework and your ApplicationContext is a plain Java class, the best options is probably to keep it in the VaadinSession.
// set context in session
VaadinSession.getCurrent().setAttribute(CONTEXT, context);
// get context from session
ApplicationContext context = (ApplicationContext) VaadinSession.getCurrent().getAttribute(CONTEXT);
Thank you very much, dear Martin.
I use Maven, is there an anologous possibility as in Spring?
My “workaround” in the moment is to collect the instances of ApplicationContext in a static HashMap with the current Session as key, which also works but is much less elegant than your recommendation.
Best, Elke