Vaadin 7 on Grails 2.x
  • Introduction
  • Project setup
    • Command Line
    • IntelliJ IDEA
    • Eclipse
    • NetBeans
    • Plugin Configuration
    • Clean up
    • Best Practices
  • Database
    • GORM
      • Create Domain Model
      • Transactions
      • LazyInitializationException
      • Open Session In View I.
      • Open Session In View II.
      • Table Container
    • Groovy SQL
      • Create Sql
      • Execute SQLs
    • MyBatis
      • Configuration
      • Basics
    • JdbcTemplate
      • Create Beans
      • Usage
    • Clean Up With Alternatives
  • Architecture
    • Model View Presenter
  • Spring Autowiring
    • Create Simple Application
    • Application With Navigator
  • UI
    • Re-using GORM Validations
    • Async Push
    • Multiple application
    • SASS Compilation
    • Widgetset Compilation
  • Spring Security
    • Spring Security Dependency
    • Spring Security Basics
    • Secured Navigator
  • Localization
    • Localization Basics
    • Custom MessageSource
  • REST
    • Without using root URL
    • Using root URL for Vaadin app
  • Plugin development
    • Github
    • Development
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3

Was this helpful?

  1. UI

Async Push

PreviousRe-using GORM ValidationsNextMultiple application

Last updated 5 years ago

Was this helpful?

Example code is available on .

Push has been added in version 7.3.0.1. Make sure you have this, or later, version of the plugin.

Step 1

Enable anyc in VaadinConfig.groovy.

asyncSupported = true

Step 2

In order to demonstrate Vaadin push, we will create a view that will create a label that will have initial value that will be overriden by a thread. The thread will wait one second and then set other text into the label. Let's say, that we replace waiting by a call to external system, where we expect a delay.

For pusing another label, we create Pusher thread that will change text of the label.

package app.views.push

import app.MyUI
import com.vaadin.navigator.View
import com.vaadin.navigator.ViewChangeListener
import com.vaadin.ui.Label
import com.vaadin.ui.VerticalLayout

class PushView extends VerticalLayout implements View {

    static final String VIEW_NAME = "push"

    Label loadingText = new Label("Loading UI, please wait...");

    @Override
    void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
        loadingText.setSizeUndefined();
        addComponent(loadingText);
        new Pusher().start();
    }

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

            MyUI.current.access(new Runnable() {
                @Override
                public void run() {
                    loadingText.setValue("Done!")
                }
            });
        }
    }
}

Step 3

Add Push annotation on your UI class.

package app

import app.views.push.PushView
import com.vaadin.annotations.Push
import com.vaadin.navigator.Navigator
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.UI

@Push
class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {

        Navigator navigator = new Navigator(this, this)
        navigator.addView(PushView.VIEW_NAME, PushView)

        navigator.navigateTo(PushView.VIEW_NAME)
    }
}
github.com/vaadin-on-grails/async-push
Vaadin plugin