FileDownloader and CssLayout

For Vaadin 8, why does the FileDownloader not work with CssLayout? It mentions that it works with all AbstractComponents, which CssLayout extends, but nothing is triggered when clicked.

I tried it with other components such as Button or Panel and the download is started as expected.

Hi,

works for me. I did the following test app:

@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        CssLayout button = new CssLayout();
        button.setWidth("100px");
        button.setHeight("100px");
        button.addStyleName("foo");
        StreamResource sr = new StreamResource(new StreamResource.StreamSource() {
            @Override
            public InputStream getStream() {
                return new ByteArrayInputStream("foo".getBytes());
            }
        }, "foo.txt");
        FileDownloader fd = new FileDownloader(sr);

        fd.extend(button);

        layout.addComponent(button);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

in my theme:

  .foo {
    background-color: red;
  }

Clicking the red CssLayout does indeed load a text file foo.txt with the content foo.

-Olli

My bad, I was still using setCaption from an example using a Button. This does not trigger the event apparently. Changing this to actually adding content to the CssLayout fixed the issue. Thanks for the reply.

Yep; as you discovered there, the caption is not a part of the component itself :slight_smile:

Good to hear you solved the issue.

-Olli