Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 2 weeks ago
Is there a better way of accessing VaadinSession beans from Spring MVC @Con
I have a use case where I need to access VaadinSession beans from Spring MVC Controller. The way I am currently doing it is too hacky and I don't even know if it is going to work with the future releases.
Is there a better way of doing it? Is there anything in Vaadin that supports the integration?
Thanks.
package app.service;
@Controller
@RequestMapping("/{uiId}")
public class DataController {
@RequestMapping(value = "/{dataId}", method = RequestMethod.GET)
public ModelAndView getData(@PathVariable Integer uiId, @PathVariable Integer dataId, HttpSession session) {
Collection<VaadinSession> vaadinSessions = VaadinSession.getAllSessions(session);
if(!vaadinSessions.isEmpty()) {
VaadinSession vaadinSession = vaadinSessions.iterator().next();
BeanStore beanStore = VaadinSessionAccessor.getBeanStore(vaadinSession, uiId);
BeanClass bean = (BeanClass) beanStore.get("*BeanName*", null);
// doing something with bean
}
ModelAndView mv = new ModelAndView();
// updating session
return mv;
}
}
////////////////
package com.vaadin.spring.internal;
import com.vaadin.server.VaadinSession;
public class VaadinSessionAccessor {
public static BeanStore getBeanStore(VaadinSession vaadinSession, int uiId) {
return ((UIScopeImpl.UIStore)vaadinSession.getAttribute("com.vaadin.spring.internal.UIScopeImpl$UIStore")).getBeanStore(new UIID(uiId));
}
}
Last updated on
You cannot reply to this thread.