I need to delay a method call, until the entire view is rendered in the client. What is the best approach to use or is there an event / method available? - From what I have read up on, there is no ‘onload’ or ‘complete’ event available.
I have also tried the ‘enter’ method and the navigator ‘afterViewChange’, however both are called before the page is rendered.
maybe try using the Component::onAttach method. I believe this should execute at that time.
@Route("test")
public class TestView extends VerticalLayout {
public TestView(){
// variant 1: add an attachListener to a component instance
addAttachListener(attachEvent -> {
// view is loaded at this point. You can for example execute javascript which relies on certain elements being in the page
});
}
// variant 2: override onAttach method of the component class
@Override
public void onAttach(AttachEvent event){
// view is loaded at this point. You can for example execute javascript which relies on certain elements being in the page
}
}
I wait until the “v-loading-indicator first” has “display:none” in his style attribute. This means that the page has loaded completely. Its not a very clever workaround since there is no event for it. So I had to make a loop that checks several times if display = none. Therefore I think the onAttach is the better solution.
Hi guys, I just wanted to provide the workaround that Philipp mentioned because it took me some time to get it to work on my side, and I’m sure the next person coming will love to copy/paste it
I couldn’t use the onAttach() solution because of some other reasons and I do believe that Vaadin could provide an easy “event listener” approach for the ‘v-loading-indicator’ because it could also be used in other cases.
Vincent Bonnefoy:
Hi guys, I just wanted to provide the workaround that Philipp mentioned because it took me some time to get it to work on my side, and I’m sure the next person coming will love to copy/paste it
loadingFinished.then(Boolean.class, (res) → {
// do something
});
I couldn't use the onAttach() solution because of some other reasons and I do believe that Vaadin could provide an easy "event listener" approach for the 'v-loading-indicator' because it could also be used in other cases.