Sub-windows when using Spring-Vaadin Integration

I’ve tried to open a subwindow from within an event handler in a Spring application (using Spring-Vaadin Integration). It’s Spring-Vaadin Integration addon v. 2.0.2, Spring version 3.1.2 and Vaadin 7.1.8. The browser log reports as follows:

INFO:  * Performing server to client RPC calls (00:16:30:398)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
SEVERE: Widget is still attached to the DOM after the connector (VerticalLayoutConnector (8)) has been unregistered. Widget was removed. (00:16:30:409 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at uHb (src/main/webapp:209:0)
    at pac (src/main/webapp:40:0)
    at yfe (src/main/webapp:31:0)
    at j7e (src/main/webapp:1:0)
    at y3b (src/main/webapp:50:0)
    at y3b (src/main/webapp:50:0)
    at A1b (src/main/webapp:43:0)
    at t1b (src/main/webapp:28:0)
    at N_b (src/main/webapp:26:0)
    at L_b (src/main/webapp:85:0)
    at c1b (src/main/webapp:1:0)
    at Rx (src/main/webapp:50:0)
    at dy (src/main/webapp:1:0)
    at (anonymous function) (src/main/webapp:95:0)
    at ck (src/main/webapp:582:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: * Unregistered 1 connectors (00:16:31:063)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: handleUIDLMessage: 35 ms (00:16:31:075)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Starting layout phase (00:16:31:528)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
SEVERE: Only managed layouts can need layout, layout attempted for nulljava.lang.IllegalStateException: Only managed layouts can need layout, layout attempted for null
    at Unknown.ji(Unknown@-1)
    at Unknown.ii(Unknown@-1)
    at Unknown.mi(Unknown@-1)
    at Unknown.oi(Unknown@-1)
    at Unknown.fnf(Unknown@-1)
    at Unknown.G5e(Unknown@-1)
    at Unknown.g5e(Unknown@-1)
    at Unknown.L5b(Unknown@-1)
    at Unknown.$5b(Unknown@-1)
    at Unknown.t1b(Unknown@-1)
    at Unknown.N_b(Unknown@-1)
    at Unknown.L_b(Unknown@-1)
    at Unknown.c1b(Unknown@-1)
    at Unknown.Rx(Unknown@-1)
    at Unknown.dy(Unknown@-1)
    at Unknown.anonymous(Unknown@-1)
    at Unknown.ck(Unknown@-1)
    at Unknown.ik(Unknown@-1)
    at Unknown.anonymous(Unknown@-1) (00:16:31:546 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at t1b (src/main/webapp:28:0)
    at N_b (src/main/webapp:26:0)
    at L_b (src/main/webapp:85:0)
    at c1b (src/main/webapp:1:0)
    at Rx (src/main/webapp:50:0)
    at dy (src/main/webapp:1:0)
    at (anonymous function) (src/main/webapp:95:0)
    at ck (src/main/webapp:582:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO:  Processing time was 60ms for 638 characters of JSON (00:16:33:243)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Referenced paintables: 7 (00:16:33:266)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Removed variable from removed component: 7 (00:16:33:708)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Removed variable from removed component: 7 (00:16:33:722)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Starting layout phase (00:16:33:734)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.ApplicationConfiguration
SEVERE: Only managed layouts can need layout, layout attempted for nulljava.lang.IllegalStateException: Only managed layouts can need layout, layout attempted for null
    at Unknown.ji(Unknown@-1)
    at Unknown.ii(Unknown@-1)
    at Unknown.mi(Unknown@-1)
    at Unknown.oi(Unknown@-1)
    at Unknown.fnf(Unknown@-1)
    at Unknown.G5e(Unknown@-1)
    at Unknown.g5e(Unknown@-1)
    at Unknown.L5b(Unknown@-1)
    at Unknown.$5b(Unknown@-1)
    at Unknown.GRe(Unknown@-1)
    at Unknown.nSe(Unknown@-1)
    at Unknown.Mk(Unknown@-1)
    at Unknown.Dk(Unknown@-1)
    at Unknown.jk(Unknown@-1)
    at Unknown.ik(Unknown@-1)
    at Unknown.anonymous(Unknown@-1) (00:16:33:758 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at o_b (src/main/webapp:1:0)
    at lk (src/main/webapp:138:0)
    at Mk (src/main/webapp:30:0)
    at Dk (src/main/webapp:282:0)
    at jk (src/main/webapp:56:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.ApplicationConfiguration
SEVERE: (TypeError)
 line: 506
 sourceURL: http://localhost:8080/com.chateauferret.sandbox/: 'null' is not an object (evaluating 'b.Mf')com.google.gwt.core.client.JavaScriptException: (TypeError)
 line: 506
 sourceURL: http://localhost:8080/com.chateauferret.sandbox/: 'null' is not an object (evaluating 'b.Mf') (00:16:35:116 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at o_b (src/main/webapp:1:0)
    at lk (src/main/webapp:138:0)
    at Mk (src/main/webapp:30:0)
    at Dk (src/main/webapp:282:0)
    at jk (src/main/webapp:56:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
MoINFO:  * Performing server to client RPC calls (00:16:30:398)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
SEVERE: Widget is still attached to the DOM after the connector (VerticalLayoutConnector (8)) has been unregistered. Widget was removed. (00:16:30:409 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at uHb (src/main/webapp:209:0)
    at pac (src/main/webapp:40:0)
    at yfe (src/main/webapp:31:0)
    at j7e (src/main/webapp:1:0)
    at y3b (src/main/webapp:50:0)
    at y3b (src/main/webapp:50:0)
    at A1b (src/main/webapp:43:0)
    at t1b (src/main/webapp:28:0)
    at N_b (src/main/webapp:26:0)
    at L_b (src/main/webapp:85:0)
    at c1b (src/main/webapp:1:0)
    at Rx (src/main/webapp:50:0)
    at dy (src/main/webapp:1:0)
    at (anonymous function) (src/main/webapp:95:0)
    at ck (src/main/webapp:582:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: * Unregistered 1 connectors (00:16:31:063)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: handleUIDLMessage: 35 ms (00:16:31:075)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Starting layout phase (00:16:31:528)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
SEVERE: Only managed layouts can need layout, layout attempted for nulljava.lang.IllegalStateException: Only managed layouts can need layout, layout attempted for null
    at Unknown.ji(Unknown@-1)
    at Unknown.ii(Unknown@-1)
    at Unknown.mi(Unknown@-1)
    at Unknown.oi(Unknown@-1)
    at Unknown.fnf(Unknown@-1)
    at Unknown.G5e(Unknown@-1)
    at Unknown.g5e(Unknown@-1)
    at Unknown.L5b(Unknown@-1)
    at Unknown.$5b(Unknown@-1)
    at Unknown.t1b(Unknown@-1)
    at Unknown.N_b(Unknown@-1)
    at Unknown.L_b(Unknown@-1)
    at Unknown.c1b(Unknown@-1)
    at Unknown.Rx(Unknown@-1)
    at Unknown.dy(Unknown@-1)
    at Unknown.anonymous(Unknown@-1)
    at Unknown.ck(Unknown@-1)
    at Unknown.ik(Unknown@-1)
    at Unknown.anonymous(Unknown@-1) (00:16:31:546 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at t1b (src/main/webapp:28:0)
    at N_b (src/main/webapp:26:0)
    at L_b (src/main/webapp:85:0)
    at c1b (src/main/webapp:1:0)
    at Rx (src/main/webapp:50:0)
    at dy (src/main/webapp:1:0)
    at (anonymous function) (src/main/webapp:95:0)
    at ck (src/main/webapp:582:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO:  Processing time was 60ms for 638 characters of JSON (00:16:33:243)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Referenced paintables: 7 (00:16:33:266)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Removed variable from removed component: 7 (00:16:33:708)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Removed variable from removed component: 7 (00:16:33:722)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.VConsole
INFO: Starting layout phase (00:16:33:734)
  at src/main/webapp:1
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.ApplicationConfiguration
SEVERE: Only managed layouts can need layout, layout attempted for nulljava.lang.IllegalStateException: Only managed layouts can need layout, layout attempted for null
    at Unknown.ji(Unknown@-1)
    at Unknown.ii(Unknown@-1)
    at Unknown.mi(Unknown@-1)
    at Unknown.oi(Unknown@-1)
    at Unknown.fnf(Unknown@-1)
    at Unknown.G5e(Unknown@-1)
    at Unknown.g5e(Unknown@-1)
    at Unknown.L5b(Unknown@-1)
    at Unknown.$5b(Unknown@-1)
    at Unknown.GRe(Unknown@-1)
    at Unknown.nSe(Unknown@-1)
    at Unknown.Mk(Unknown@-1)
    at Unknown.Dk(Unknown@-1)
    at Unknown.jk(Unknown@-1)
    at Unknown.ik(Unknown@-1)
    at Unknown.anonymous(Unknown@-1) (00:16:33:758 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at o_b (src/main/webapp:1:0)
    at lk (src/main/webapp:138:0)
    at Mk (src/main/webapp:30:0)
    at Dk (src/main/webapp:282:0)
    at jk (src/main/webapp:56:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)
Mon Dec 09 00:16:29 GMT+000 2013 com.vaadin.client.ApplicationConfiguration
SEVERE: (TypeError)
 line: 506
 sourceURL: http://localhost:8080/com.chateauferret.sandbox/: 'null' is not an object (evaluating 'b.Mf')com.google.gwt.core.client.JavaScriptException: (TypeError)
 line: 506
 sourceURL: http://localhost:8080/com.chateauferret.sandbox/: 'null' is not an object (evaluating 'b.Mf') (00:16:35:116 | error)
    at YFb (src/main/webapp:1:0)
    at jHb (src/main/webapp:103:0)
    at iHb (src/main/webapp:71:0)
    at vHb (src/main/webapp:130:0)
    at o_b (src/main/webapp:1:0)
    at lk (src/main/webapp:138:0)
    at Mk (src/main/webapp:30:0)
    at Dk (src/main/webapp:282:0)
    at jk (src/main/webapp:56:0)
    at ik (src/main/webapp:59:0)
    at (anonymous function) (src/main/webapp:286:0)

and the window in question appears without any content, just empty and small and in the wrong place.

When I do it without Spring it works. It also works if I attach the window in the main thread instead of in an event handler. It makes no difference if I inject the window or if I also inject the layout into the window class. My minimal UI class code is as follows:

@Component
@Scope("prototype")
public class MyUI extends UI {

    @Autowired
    private transient ApplicationContext applicationContext;
    
    
    
 
    public MyUI() {
        super();
    }
     
    
    @Override
    protected void init (final VaadinRequest request) {
        

        ComponentContainer pageLayout = new VerticalLayout();
        setContent (pageLayout);
        
        
        Button button = new Button ("MyUI subwindow");
        button.addClickListener (new ClickListener()  {
        @Override
            public void buttonClick (ClickEvent e) {
                VerticalLayout subContent = new VerticalLayout ();
                Window subWindow = new Window ("title", subContent);
                subContent.setMargin (true);
                subContent.addComponent (new Label ("Window produced from button click handler"));
                subContent.addComponent (new Button ("OK"));
                subWindow.center();
                UI.getCurrent().addWindow (subWindow);
        
            }
        });
        pageLayout.addComponent (button);
        
        
        VerticalLayout subContent = new VerticalLayout ();
        Window subWindow = new Window ("title", subContent);
        subContent.setMargin (true);
        subContent.addComponent (new Label ("Window produced from MyUI.init method"));
        subContent.addComponent (new Button ("OK"));
        subWindow.center ();
        UI.getCurrent().addWindow (subWindow);        
        
        
    }

    @Override
    public void markAsDirty () {
    
    }

I’ve seen just one report of something like this before, but I don’t think Spring or S-V integration were suspected in that case. If there’s a possible defect it might be on the S-V Integration side rather than in Vaadin. What does anyone think? Or am I doing something wrong, should I be obtaining an object from the application class and calling addWindow() on that?

Hello Martin,

Is the code you attached the one that is working or the one that causes the problem?

-Petter-

There are two calls to UI.getCurrent().addWindow() in my example. The one in the button’s click handler doesn’t work. The one directly in the main thread of the init() method does work, and is just there to help illustrate the difference. This makes me think that the issue is to do with whether you’re in the main thread or not. UI.getCurrent() returns the expected UI object no matter where it’s called, as one would expect. If you run the above code, you get one subwindow rendered properly as soon as the UI is built, and a button. If you click the button you should get another subwindow similar to the first, but what you actually get is an empty subwindow with some strange behaviours and in the wrong place, and all those error messages in the browser log.

Bit of further research. I happen to have a copy of the Vaadin 7 Cookbook by Jaroslav Holaň and Ondřej Kvasnovský. In Chapter 8 of that book there are various examples of Spring and Vaadin applications that use annotation-driven application contexts (instead of XML, which I was using), and don’t require add-ons to be installed. So I compiled number 6 and added to the UI class a button which brings up a subwindow (exactly the code in my example at the top) and it seems to work.

I don’t suppose it can be to do with whether I use XML or annotations to specify the application context, so unless anyone can see something I can’t I’d better raise it as an issue for Spring-Vaadin Integration and let Alexander Fedorov have a look at it.