- Vaadin 7 Cookbook
- Jaroslav Holaň Ond?ej Kvasnovsk?
- 621字
- 2021-07-23 14:19:32
Running Vaadin on Grails
Grails is a web application framework, which uses the Groovy language, following the coding by convention paradigm. All the information about Grails can be found at the following link:
The Grails plugin called vaadin
integrates Vaadin into the Grails project. Therefore, we can use Vaadin as a replacement for the Grails view layer. Instead of writing HTML, CSS, and JavaScript, we make Vaadin view in Groovy. More information about the Vaadin integration is available at the following web page:
We are going to make a simple Vaadin application that will be running on Grails and written in Groovy.
Getting ready
Install the Eclipse Groovy/Grails Tool Suite (GGTS). download link is available at the Grails pages at http://grails.org/products/ggts.
How to do it...
Carry out the following steps in order to create a new Grails project with Vaadin:
- Open File | New | Grails Project.
- Fill in the name of the project and finish the New Grails Project wizard.
- Click on the Grails icon, which opens the console that we use for running the Grails command. In this step, we just want to make sure the project is created properly. Run the
run-app
command. - The Grails application is opened up in the browser window using
http://localhost:8080/vaadin-in-grails
. It still uses.gsp
files, which we replace with Vaadin in the next step. - Install the Vaadin plugin. Open up the Grails console and run the following command:
install-plugin vaadin
- Mark the
grails-app/vaadin
folder as the source folder. - Run the application again and open
http://localhost:8080/vaadin-in-grails
in the browser. Vaadin has replaced the Grails view.
How it works...
We have made a Grails project where we have replaced the Grails view layer with a Vaadin framework. The integration between Grails and Vaadin is done by the Grails plugin that is connecting these two frameworks. As you have experienced, the Vaadin plugin is available via the Grails plugin system (http://grails.org/plugin/vaadin).
Let's have a close look at what the Vaadin plugin has generated for us.
The MyUI.groovy
file has been generated inside the grails-app/vaadin
source folder. MyUI
represents the Vaadin user interface, which is shown to the user in the browser window.
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 vaadinRequest) { VerticalLayout layout = new VerticalLayout() String homeLabel = Grails.i18n("default.home.label") Label label = new Label(homeLabel) layout.addComponent(label) setContent(layout) } }
We should store all the Vaadin code we create inside the grails-app/vaadin
source folder.
The Vaadin plugin needs to have information about the location of the MyUI
class in order to add that information to the web.xml
deployment descriptor. Therefore, a new file VaadinConfig.groovy
has been generated inside the grail-app/conf
folder.
vaadin { mapping = [ "/*": "app.MyUI" ] productionMode = false } environments { production { vaadin { productionMode = true } } }
In VaadinConfig.groovy
, we can change the path to the UI class. We can also add more UI classes.
vaadin { mapping = [ "/*": "app.MyUI", "/ui/*": "app.YourUI" ]
The last thing which has been done during the plugin installation is the removal of the URL mapping inside the UrlMappings.groovy
file.
See also
- More about Grails can be learned from the manual at http://grails.org/doc/latest
- We will explore Grails and Vaadin integration in Chapter 8, Spring and Grails Integration
- 解析QUIC/HTTP3:未來互聯(lián)網(wǎng)的基石
- 物聯(lián)網(wǎng)工程規(guī)劃技術(shù)
- SEO 20日
- Learning QGIS 2.0
- 計算機網(wǎng)絡(luò)安全實訓(xùn)教程(第二版)
- Mastering JavaFX 10
- 6G新技術(shù) 新網(wǎng)絡(luò) 新通信
- C/C++串口通信:典型應(yīng)用實例編程實踐
- Bonita Open Solution 5.x Essentials
- VMware NSX網(wǎng)絡(luò)虛擬化入門
- 夢工廠之材質(zhì)N次方:Maya材質(zhì)手冊
- 網(wǎng)絡(luò)AI+:2030后的未來網(wǎng)絡(luò)
- React Cookbook
- 網(wǎng)絡(luò)工程實施技術(shù)與方案大全
- 全聯(lián)網(wǎng)標識服務(wù)