jueves, 1 de octubre de 2020

34. Understanding ui.access(). @Push annotation

 0. Introduction

I want to show only a few remarks about "Asynchronous Updates" from Vaadin tutorial.

When you run a thread,  the Session seems to be not accessible, so the UI. You should take it into account as when manipulating form components from the thread!!!


1. Hanging the execution

Be very careful as the execution may hang in these cases:

  • When using the annotation @Push without options and the process is executed for the first time. Maybe I am doing something wrong but I don't know.
  • When using the annotation @Push( (PushMode.MANUAL) and not using ui.push() as the final sentence inside a ui.access()(() -> {...}) block; to assure the UI is updated
  • When using ui.push(), my advice is to put it into a try-catch block!
  • In Vaadin-14 use the @Push annotation in the main form, but in Vaadin-17 use it in the class that implements AppshellConfigurator. As it is explained in the next post.

ui.access(() -> {
  Span sp=new Span("Begin command...");
  view.add(sp);
  try {ui.push()} catch (Exception e){e.printstacktrace()}; //Last sentence 
});


2. Creating components dynamically from a thread

Components should be created within the ui.access() {} block, as you cannot access the Session or the UI outside this block. 

For instance, you cannot create an Anchor component outside this block as the creation implies access to the UI for getting URIs!!

In case you can create the component, you cannot attach it to the UI outside this block!

No hay comentarios:

Publicar un comentario