aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/articles/VaadinOnGrailsMultipleUIs.asciidoc
blob: 31c6785e2b523f4cebd908fd927c28e4eebc7f91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: Vaadin On Grails Multiple UIs
order: 37
layout: page
---

[[vaadin-on-grails-multiple-uis]]
= Vaadin on grails - multiple UIs

_Versions used in this tutorial: Grails 2.3.x, Vaadin 7.1.x. News and
updates about Vaadin on Grails are available on
https://twitter.com/VaadinOnGrails[VaadinOnGrails]. This is continuation
of <<VaadinOnGrailsDatabaseAccess#, Vaadin on Grails - Database access>>_

In `grails-app/conf/VaadinConfig.groovy`, we can change URL mapping to
UI. Also, we can define multiple UIs to be accessible from one Grails
application.

Create two new UIs that we will show under different URLs. `ClientUI`
will be available on http://localhost:8080/client and `ServerUI` on
http://localhost:8080/server

[source,java]
....
class ClientUI extends UI {
  protected void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout()
    layout.setMargin(true)
    Label label = new Label("Client")
    layout.addComponent(label)
    setContent(layout)
  }
}

class ServerUI extends UI {
  protected void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout()
    layout.setMargin(true)
    Label label = new Label("Server")
    layout.addComponent(label) setContent(layout)
  }
}
....

Open `VaadinConfig.groovy` and change the mapping, so the mapping points
to the new UIs.

....
mapping =
[ "/client/*": "app.ClientUI",
  "/server/*": "app.ServerUI"]
....

Now we can start up the application and access both URLs to see each is
mapped to different UI class.

image:http://vaadinongrails.com/img/mapping-uis.png[Mapping UIs]