2

I've got several Layout components, added as tabs, in Vaadin that execute time-consuming operations to display some values. In order to minimize the computation time I'd like to execute the time-consuming operation only if the concerning panel/layout becomes visible. I've tried common event listeners but they didn't get fired. In Swing I'm used to react on such events. But how do you do it in Vaadin?

    gridLayout.addComponentAttachListener(new ComponentAttachListener()
    {
        @Override
        public void componentAttachedToContainer(
                final ComponentAttachEvent event)
        {
            System.err.println("attach-listener-" + event);
        }
    });

    gridLayout.addLayoutClickListener(new LayoutClickListener()
    {
        @Override
        public void layoutClick(final LayoutClickEvent event)
        {
            System.err.println("layoutclick" + event);
        }
    });

It's important to realize a "lazy loading" for these UI container's content. I'm convinced that I'm not the only one that ever tried to realize this. What would be your approach?

PAX
  • 888
  • 11
  • 29
  • It seems that Javascript misses such an event (shown/disappeared in viewport) for arbitrary DOM elements. That's why Vaadin has troubles to realize this event on components: https://stackoverflow.com/questions/1462138/js-event-listener-for-when-element-becomes-visible – PAX Oct 17 '17 at 06:01

1 Answers1

1

In case you are actually using TabSheet you can first add empty layouts on the tabs and then listen for tab selection change events. There you can fill the empty layout with your costly operations.

cfrick
  • 29,743
  • 4
  • 46
  • 59