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
  • Step 4
  • Step 5

Was this helpful?

  1. Spring Autowiring

Application With Navigator

PreviousCreate Simple ApplicationNextUI

Last updated 5 years ago

Was this helpful?

Example code is available on .

In this tutorial we will show how to initialize Navigator and how to implement View.

The first two steps are the same as for the previous 'Create Simple Application'.

Step 1

We need to say the plugin that we want to do annotation based URL mapping. Comment out mapping from VaadinConfig.groovy to do that.

vaadin {
//    mapping = [
//            "/*": "app.MyUI"
//    ]
}

Step 2

Now we will create a dummy service ItemService that we will autowire in Vaadin code.

package app

import grails.transaction.Transactional

@Transactional
class ItemService {

    String serviceMethod() {
        return 'Value from service'
    }
}

Step 3

In this step we will do the following things:

  • Create new UI that extends DefaulUI

  • Use @VaadinUI annotation to do URL mapping for MyUI

  • Call super.init(r) method that will initialize the navigator

After the point mentioned above are done, we can use Views class to open a view. Continue to the next step to learn how views are registered using @VaadinUI annotation.

package app

import com.vaadin.grails.navigator.Views
import com.vaadin.grails.ui.DefaultUI
import com.vaadin.grails.ui.VaadinUI
import com.vaadin.server.VaadinRequest

@VaadinUI(path = '/')
class MyUI extends DefaultUI {

    @Override
    protected void init(VaadinRequest r) {
        super.init(r)

        Views.enter(ItemView)
    }
}

Step 4

Before we use Views.enter(View) method we need to tell the pluging where are the views and what is the URL path to them.

Add @VaadinUI annotation to every view that should be accesible by Views.enter method.

package app

import com.vaadin.grails.navigator.VaadinView
import com.vaadin.navigator.View
import com.vaadin.navigator.ViewChangeListener
import com.vaadin.ui.Label
import com.vaadin.ui.VerticalLayout
import org.springframework.beans.factory.annotation.Autowired

@VaadinView(path = "item")
class ItemView extends VerticalLayout implements View {

    @Autowired
    ItemService itemService

    @Override
    void enter(ViewChangeListener.ViewChangeEvent e) {
        setMargin(true)

        String label = itemService.serviceMethod()
        addComponent(new Label(label))
    }
}

Step 5

Run the application grails run-app and open in a browser.

Running application with Navigator
github.com/vaadin-on-grails/spring-autowiring-navigator
http://localhost:8080/spring-autowiring-navigator