PUSH not updating UI

Hi,

i want to update the UI every 10 seconds.
What i did was:

<init-param> <param-name>pushmode</param-name> <param-value>automatic</param-value> </init-param> <async-supported>true</async-supported> Add this to my web.xml.

Added the @Push annotation to my UI class.
Now im trying to update the UI from another “View”-class.

/*
/ ...
*/

public MyClass(Navigator navigator) {
      test();
   }

   class InitializerThread extends Thread {
      
      public InitializerThread() {
         b.setValue("TestValue");
      }
      
      @Override
      public void run() {
         try {
            Thread.sleep(10000);
         } catch (InterruptedException e) {
         }
         UI.getCurrent().access(new Runnable() {
            @Override
            public void run() {
               b.setValue("NewTestValue updated");
               System.out.println(UI.getCurrent().getPushConfiguration().getPushMode());
              }
         });
      }
   }

   private void test() {
      new InitializerThread().start();
   }

In my console i see printed out “AUTOMATIC” for the push mode.
When i look at the debugging console of vaadin i get:

Communication methodPush (websocket) (poll interval 3000ms) Heartbeat300s Is there anything i can try to solve this problem?
Vaadin version: 7.2.2

Hi Joshua,

I think what you are missing is to actually push the changes. Try to put the line ‘UI.getCurrent().push();’ at the end of your run-method.

Hi Dennis,

thank you for your quick response.
I’ve tried this already many times but it’s still the same problem. But it also wouldn’t make any sense cause I put the method on automatic and not manual or am i wrong?

Thank you.

If you have automatic you don’t need to manually push changes.
I would suggest defining the pushmode inside the annotation and not inside web.xml.
Also: Do you have vaadin-push in your classpath/dependency?
More information:
https://vaadin.com/wiki/-/wiki/Main/Enabling+server+push

Yes i got the dependency in my pom.xml like written in the guide.

Deleting the pushmode from the web.xml and adding it to the UI class itself

@Push(value = PushMode.AUTOMATIC) @Theme("TicketTheme") @PreserveOnRefresh public class MyUI extends UI { didn’t change anything either :frowning:

FYI: Changing it to MANUAL and doing the push on my own doesn’t work either :frowning:

That’s really weird. I justed it with your setup and it worked perfectly. Could you check if there might be some error in your logic. Maybe b isn’t added to the UI and you’re looking at another Label…
You could also try to create a new fresh Project and try it there. Maybe some setting screwed up.

“i want to update the UI every 10 seconds.”
it looks like you need polling not push. Just add

@Override protected void init(VaadinRequest request) { setPollInterval(10000); ... } for refreshing UI every 10 sec.
BTW. Push also needs Observer.

I’m looking at the right label… That’s why i change the label in the constructor:

public InitializerThread() { b.setValue("TestValue"); } I already tried it with setting the poll interval.

That’s strange. Well I’m going to try a few more things…
I’ll tell you if I found the problem :confused:

Thank you guys.

If even poll didn’t work there might be a problem inside atmosphere or some server/browser issue.
So creating a new project might solve it if atmosphere gets redownloaded.
Other then that you could try testing it on another server or browser (though i suspect the problem more inside atmosphere…)

Annotations are only good for situations in which every deployment must have it. We use web.xml because it’s an easy edit and restart to switch among disabled/automatic, as well as the transport being streaming/long-polling, etc. And we can do it on one deployment without forcing it on others. Annotations mean changing the code and re-releasing it before a restart.

We have found that push still isn’t working well enough over the Internet, so our ability to turn it on/off is key. We still have issues with PDF downloads via a FileDownloader (with dynamic content created via overridden getStream()) being swallowed and then getting broken pipe exceptions when push is automatic and transport is long-polling. (So close, but PDF downloads are rather a key need in our app.)