2

How do I apply Vaadin7 server push to a Navigated View. Basically I want to up date MyView class table components. Since Its a navigated View its not working as explained in Vaadin. Is there Any other way to update data from MyView class? such as inserting the thread in it.

UI class

@Push
public class MyUI extends UI{

Navigator  navigator;

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyUI.class, widgetset = "com.example.myui.MyuiWidgetset")
public static class Servlet extends VaadinServlet {
}
    @Override
    protected void init(VaadinRequest request) {
        new Navigator(this, this);
        getNavigator().addView(MyView.MYVIEW, MyView.class);
        new InitializerThread().start();
    }
}

class InitializerThread extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            access(new Runnable() {
                @Override
                public void run() {
                   //update MyView's table from this event
                }
            });
        }
    }
}

View Class

public class MyView extends CustomComponent implements View
{
    public MainView()
    {
    final Table table = new Table();
    table.addContainerProperty("Date & Time", String.class, null);
    table.setSelectable(true);
    table.setSizeFull();
    table.setImmediate(true);

    while(){
      table.addItem(new Object[]{new Date()}, new String(""));
    }
}
Swarne27
  • 5,521
  • 7
  • 26
  • 41

1 Answers1

1

In MyView you can register your class instance in MyUI. So you have then access to the MyView instance and update it.

But perhaps you should have the background thread running inside of MyView instead? It does not make sense to update MyView when it's not displayed...

André Schild
  • 4,592
  • 5
  • 28
  • 42
  • In my case: Push works fine when I am in the same view but doesn't works if I am manually navigating from one view to another. Any idea about that ? – Milesh Jun 09 '16 at 03:35
  • It would be great if you added some code to show us how to do that. – Pere Jan 26 '17 at 15:57