1

I have page with grid. I am loading data through service to grid. Loading and computing all data takes about 20-40 seconds. When I press button to get data, page start loading (classical in vaadin top loading indicator start loading).

My question is, how can I stop loading/waiting for data?

I can't stop searching process on that server I am getting data from, it dont have this functionality, I can only request for data, and wait for them.

Should I stop some thread? should i use something like this.getUI... and somewhere here stop it?

I am using vaadin 7.7.4

Thank you :)

NoPa147
  • 49
  • 3

2 Answers2

2

You should use threads for this.

You will need to separate your logic, that the main thread does add all components to the UI. This thread then also needs to spawn a new thread which does fetch the data and then updates the UI accordingly.

To update the UI once the data has been fetched from the backend you will need to activate push in your UI.

Don't forget to synchronise thread access to the UI with something like:

ui.access(new Runnable() {
    @Override
    public void run() {
        ...grid_update_with_new_data... ;
    }
});

The fetching of the data should occur outside the ui.access method, otherwise your UI will freeze during backend data loading.

See this post for more technical details

Using Thread with Vaadin? and https://vaadin.com/docs/v7/framework/advanced/advanced-push.html

André Schild
  • 4,592
  • 5
  • 28
  • 42
0

@André Schild This is simplified code. When I hit search button, app start searching, no problem with that. Problem is how to STOP searching, before its done. Enough for me is to stop waiting for response, and stop loading bar at top of the page, but I dont know how to achive this.

@SpringComponent
@UIScope
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DistraintSearchComponent extends CustomComponent {

 @Autowired
 private Service service
 private Button searchButton = new Button("Search");

 public void init(){
  searchButton.addClickListener(new ClickListener() {

  @Override
  public void buttonClick(ClickEvent event) {
   List<Results> results = service.findByFilter(filter);
   refreshGrid(results);
  }

  });
 }
}
NoPa147
  • 49
  • 3