spring icon indicating copy to clipboard operation
spring copied to clipboard

Multi UI SpringViewDisplay issue

Open k-komarov opened this issue 8 years ago • 7 comments

Check this please https://vaadin.com/forum#!/thread/14578757

k-komarov avatar Nov 27 '16 21:11 k-komarov

Here is a demo application to reproduce the issue https://github.com/k-komarov/vaadin-spring-demo.

k-komarov avatar Nov 30 '16 21:11 k-komarov

@hesara Could you give a quick look at this issue? I think you have the best knowledge on this.

mstahv avatar Dec 07 '16 09:12 mstahv

Any updates on this issue?

emanuelnastasa avatar Oct 19 '17 15:10 emanuelnastasa

@k-komarov , do you have workaround the issue?

maksaimer avatar Oct 26 '17 19:10 maksaimer

I've used vaading-spring 2.1-SNAPSHOT, this issue still exists.

olive009 avatar Nov 03 '17 10:11 olive009

I have workaround the issue, extends from SpringVaadinServlet and override method servletInitialized

public class CustomSpringVaadinServlet extends SpringVaadinServlet {

    @Override
    protected void servletInitialized() throws ServletException {
        VaadinServletService service = getService();
        service.addSessionInitListener(new SessionInitListener() {

            private static final long serialVersionUID = -6307820453486668084L;

            @Override
            public void sessionInit(SessionInitEvent sessionInitEvent)
                    throws ServiceException {
                WebApplicationContext webApplicationContext = WebApplicationContextUtils
                        .getWebApplicationContext(getServletContext());

                // remove DefaultUIProvider instances to avoid mapping
                // extraneous UIs if e.g. a servlet is declared as a nested
                // class in a UI class
                VaadinSession session = sessionInitEvent.getSession();
                List<UIProvider> uiProviders = new ArrayList<UIProvider>(
                        session.getUIProviders());
                for (UIProvider provider : uiProviders) {
                    // use canonical names as these may have been loaded with
                    // different classloaders
                    if (DefaultUIProvider.class.getCanonicalName().equals(
                            provider.getClass().getCanonicalName())) {
                        session.removeUIProvider(provider);
                    }
                }

                // add Spring UI provider
                SpringUIProvider uiProvider = new CustomSpringUIProvider(session);
                session.addUIProvider(uiProvider);
            }
        });
        service.addSessionDestroyListener(new SessionDestroyListener() {
            @Override
            public void sessionDestroy(SessionDestroyEvent event) {
                VaadinSession session = event.getSession();

                UIScopeImpl.cleanupSession(session);
                VaadinSessionScope.cleanupSession(session);
            }
        });
    }
}

Only one line differ from base line: SpringUIProvider uiProvider = new CustomSpringUIProvider(session); And CustomSpringUIProvider:

public class CustomSpringUIProvider extends SpringUIProvider {
    public CustomSpringUIProvider(VaadinSession vaadinSession) {
        super(vaadinSession);
    }

    @Override
    public UI createInstance(UICreateEvent event) {
        final Class<UIID> key = UIID.class;
        final UIID identifier = new UIID(event);
        CurrentInstance.set(key, identifier);
        try {
            logger.debug(
                    "Creating a new UI bean of class [{}] with identifier [{}]",
                    event.getUIClass().getCanonicalName(), identifier);
            UI ui = getWebApplicationContext().getBean(event.getUIClass());

            getSpringViewDisplayRegistrationBean().setBeanClass(event.getUIClass());

            configureNavigator(ui);
            return ui;
        } finally {
            CurrentInstance.set(key, null);
        }
    }

    private SpringViewDisplayRegistrationBean getSpringViewDisplayRegistrationBean() {
        return getWebApplicationContext().getBean(SpringViewDisplayRegistrationBean.class);

    }
}

getSpringViewDisplayRegistrationBean().setBeanClass(event.getUIClass()); - before configure navigator I register UI class

It works for me, but i wait fix the issue.

maksaimer avatar Nov 03 '17 11:11 maksaimer

@maksaimer I used you code, but shows the error: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.vaadin.spring.internal.SpringViewDisplayRegistrationBean' available

olive009 avatar Nov 04 '17 13:11 olive009