Native window and printing

Hi,

I really need to be able to open a new native window with some content in it to print.
The book of Vaadin has a section for that: https://vaadin.com/book/vaadin7/-/page/advanced.printing.html

But it seems that it is old stuff! Made for Vaadin 6. The example is not working at all.

How can I achieve the same thing in Vaadin 7??

Please help!

Hi Thierry.

Button print = new Button("Print This Page");
print.addClickListener(new Button.ClickListener() {
    public void buttonClick(ClickEvent event) {
        // Print the current page
        JavaScript.getCurrent().execute("print();");
    }
});

This code should work with Vaadin 7. But only if the root class is a Window. An UI opens an empty chrome print window.

 Button open = new Button("Open Window");
        open.addClickListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent event) {
                
                Button print = new Button("Print This Page");
                print.addClickListener(new Button.ClickListener() {
                    public void buttonClick(Button.ClickEvent event) {
                        // Print the current page
                        JavaScript.getCurrent().execute("print();");
                    }
                });
                Window w = new Window("My window to print", print);
                getUI().addWindow(w);
            }
        });

yourUiSubclass.addComponent(open);

Check out this thread https://vaadin.com/forum/-/message_boards/view_message/2642362