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
  • Step 6

Was this helpful?

  1. REST

Using root URL for Vaadin app

PreviousWithout using root URLNextPlugin development

Last updated 5 years ago

Was this helpful?

Example code is available on .

URL mapping can be done also in way we use / root URL to display Vaadin application. In this article, we are going to show how to do it.

Step 1

Create mapping in UrlMapping.groovy as follows:

class UrlMappings {

    static mappings = {
        "/" {
            controller = "redirect"
        }
        // add your URL mapping for controllers
        group "/rest", {
            "/$controller/$action?/$id?"()
        }
    }
}

Step 2

Then we need to create the controller that will redirect the request to the Vaadin application.

package app

class RedirectController {

    def index() {
        redirect(uri: "/app")
    }
}

Step 3

Last step is to make sure that VaadinConfig.groovy contains mapping to Vaadin UI class.

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

Step 4

Create a controller and implement some logic there. For example, fetch some data from database and return it as JSON.

package app

class RedirectController {

    def index() {
        redirect(uri: "/app")
    }
}

Step 5

Create two sample Vaadin UI, so we can verify URL mapping.

package app

import com.vaadin.ui.UI
import com.vaadin.ui.VerticalLayout
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.Label
import com.vaadin.grails.Grails

class MyUI extends UI {

    @Override
    protected void init(VaadinRequest r) {

        VerticalLayout layout = new VerticalLayout()
        layout.setMargin(true)

        String homeLabel = Grails.i18n("default.home.label")
        Label label = new Label(homeLabel)
        layout.addComponent(label)

        setContent(layout)
    }
}

Step 6

Start up the application and try out these URLs:

redirects user to application

displays JSON response

github.com/vaadin-on-grails/rest-with-root
http://localhost:8080/rest-with-root
http://localhost:8080/rest-with-root/rest/item