Coding

Vaadin on Grails - Create project in IntelliJ IDEA

Versions used in this tutorial: Grails 2.3.x, Vaadin 7.1.x. News and updates about Vaadin on Grails are available on VaadinOnGrails

In this tutorial we will show how to create and setup Grails project together with Vaadin, in IntelliJ IDEA. These two frameworks Grails and Vaadin are integrated together with this plugin.

First we need to setup Grails with IDE, IntelliJ IDEA 13 in this tutorial. Or we could get Groovy/Grails Tool Suite which is without any fees.

Setup IDE #

  1. Go to http://grails.org/download and get the latest version of Grails
  2. Unpack it on your local computer and start up IntelliJ IDEA
  3. Open the New Project window and select Grails from the list. Click on Create... button and then select the root of your unpacked Grails archive.

Create New Project #

  1. Fill in the name of the project and choose the latest version of Grails.
  2. Click on Finish and on the next dialog, choose Run 'create app'
  3. Open file
    BuildConfig.groovy
    and add new plugin as follows:
    compile ":vaadin:7.1.11"
    . The latest version of the plugin is always available on http://grails.org/plugin/vaadin
  4. We have to disable Grails to take control over the URLs, so Vaadin can do it. Open
    UrlMappings.groovy
    file and remove the mapping, so the content of the file is the following:
    class UrlMappings {

static mappings = {} } }}}If you see this error, run grails again and compile it again. There an issue with grails and it is not possible to compile the project in the first run.

target/work/plugins/vaadin-7.1.11/scripts/_Events.groovy: 1: unable to resolve class com.vaadin.grails.VaadinConfiguration@ line 1, column 1.import com.vaadin.grails.VaadinConfiguration }}} 

  1. Now we want Vaadin plugin to generate the mandatory files in order to be able to run Vaadin application. On the right side in the menu, there is a launch button, click on that one. You can also press
    Alt+Cmd+G
    on Mac OS or
    Ctrl+Alt+G
    on Windows and type
    run-app
    command there.
  2. Mark
    grails-app/vaadin
    folder as a source folder in IDE.
  3. Run the application again and a Vaadin application with a single Home label will be available on http://localhost:8080/ria-app in your browser.

Developing #

All the Vaadin code should be placed in

grails-app/vaadin
folder. All the other classes that are not UI related can be put to
src/groovy
or
src/java
.

Open the generated

MyUI.groovy
file, edit the content a bit and save the file. See that the class has been recompiled and when you refresh the page, it gets automatically updated. You don't have to restart the application or use JRebel for small changes. But if we change the application context, add a new bean, change method signature and other 'big' changes, we have to restart the application.

Now you can continue with Vaadin on Grails - Database access

0 Attachments
8974 Views
Average (0 Votes)
Comments
Hi,

Great job and thanks for the post. However I have tried the steps above on GGTS and Netbeans and even though it works, the IDE flags the vaadin imports as unable to resolve them and as a result code completion does not work for Vaadin components

It appears the plugin did not resolve its dependencies.

Also I notice the first time I run the app for Vaadin plugin to setup files as in step 5 I get the following error:

|Installed plugin vaadin-7.1.9.1
......Error
|
Error loading event script from file [target\work\plugins\vaadin-7.1.9.1\scripts\_Events.groovy] startup failed:
C:\ .....\target\work\plugins\vaadin-7.1.9.1\scripts\_Events.groovy: 1: unable to resolve class com.vaadin.grails.VaadinConfiguration
@ line 1, column 1.
import com.vaadin.grails.VaadinConfiguration
^
1 error
(Use --stacktrace to see the full trace)


Please help with this thanks...
Posted on 2/1/14 11:46 AM.
Oh! yeah got it now.

Right click on project -> Grails Tools -> Resolve dependencies
Posted on 2/2/14 1:12 AM.
Hi,

I'm getting the following error when I Run Target (full output at the end of this post):
Error creating bean with name 'transactionManager'

I'm using Grails version 2.4.4, Vaadin version 7.3.7 and IntelliJ IDEA Ultimate 14.0.2

Any ideas?

Thanks,
Peter

| Error 2015-01-17 12:47:05,334 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by IntegrationException: Error activating Bean Validation integration
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by NoClassDefFoundError: javax/validation/ParameterNameProvider
->> 760 | defineClass in java.lang.ClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 142 | defineClass in java.security.SecureClassLoader
| 455 | defineClass in java.net.URLClassLoader
| 73 | access$100 in ''
| 367 | run . . . in java.net.URLClassLoader$1
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 269 | configure in javax.validation.Validation$GenericBootstrapImpl
| 111 | buildDefaultValidatorFactory in javax.validation.Validation
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ClassNotFoundException: javax.validation.ParameterNameProvider
->> 372 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 760 | defineClass in ''
| 142 | defineClass in java.security.SecureClassLoader
| 455 | defineClass in java.net.URLClassLoader
| 73 | access$100 in ''
| 367 | run . . . in java.net.URLClassLoader$1
| 361 | run in ''
| 360 | findClass in java.net.URLClassLoader
| 424 | loadClass in java.lang.ClassLoader
| 269 | configure in javax.validation.Validation$GenericBootstrapImpl
| 111 | buildDefaultValidatorFactory in javax.validation.Validation
| 266 | run . . . in java.util.concurrent.FutureTask
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Error |
Forked Grails VM exited with error
|Server running. Browse to http://localhost:8080/grailstest
Posted on 1/17/15 11:56 AM.
Caused by NoClassDefFoundError: javax/validation/ParameterNameProvider
->> 760 | defineClass in java.lang.ClassLoader

==>

you may define hibernate-validator jar as a runtime dependency in the BuildConfig.groovy like so:

dependencies {
....
runtime 'org.hibernate:hibernate-validator:5.1.1.Final'
}
Posted on 1/27/15 1:27 PM in reply to Peter Sedman.