How to update content in a vaadin tab on selection change?

2.1k views Asked by At

I have a Vaadin tab menu, each tab contains of course different content. Now, if the content is an own class with dynamically generated content, how can I force the content to be updated if a tab is selected?

My content class implements View, thus it as a enter(ViewChangeEvent event) that would be normally triggered if I use the Navigator to change the view. However, then I use a tab to change the content, there is no ViewChangeEvent fired. How can I though trigger the enter() method of the specific view content of the tab?

@VaadinComponent
@UIScope
public class MyView extends CssLayout implements View {
    private Label label;

    public MyView() {
        label = new Label("empty");
    }

    @Override
    public void enter(ViewChangeEvent event) {
        label.setValue("entered");
    }
}

@VaadinComponent
@UIScope
public class MyMenu extends CssLayout {
    private TabSheet tabs;

    public MyMenu() {   
        tabs = new TabSheet();
        addComponent(tabs);     
    }

    @Autowired
    private MyView myview;

    @PostConstruct
    public void init() {
        tabs.addComponent(myview);
        //some more tabs
    }
}
1

There are 1 answers

0
Paolo Forgia On BEST ANSWER

You can use a Shortcut Listener like that

component.addShortcutListener(new ShortcutListener("caption", KeyCode.ENTER, null) {

    private static final long serialVersionUID = 1L;

    @Override
    public void handleAction(Object sender, Object target) {
        label.setValue("entered");
    }
});