Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin Grails Plugin
Hi All,
I finally tried integrating Vaadin with Grails to see if it was possible to develop a Vaadin application without having to constantly redeploy in order to see my progress. The result is a new Vaadin Grails plugin, and I was very impressed with the increase in productivity. For details, check out the plugin here, or install the it in your Grails app like this:
grails install-plugin vaadin
Have fun!
Daniel
Added a short notice about it on the wiki: http://vaadin.com/wiki/-/wiki/Main/Grails%20plugin
Daniel,
Can you post a simple Hello World on integrating Vaadin and Grails using your plugin?
Also, what are your plans for maintaining the plugin, going forward ... as new versions of Vaadin and Grails become available?
Joet
Hi Joe,
My original plans for the plugin were dependent on the response that it received. Recently a few people have requested information about the plugin, so I've decided to actively maintain it, starting this week. You can track my progress, or vote for features or issues for the plugin on its Codehaus JIRA page. My first priority is to update the plugin to the latest version of Vaadin. After that, I plan to write a Hello World example and post it on the wiki here. Hopefully that will be some time this week.
Regards,
Daniel
Hi Daniel,
I tried Vaadin Grails Plugin but I get following exception when accessing a one-to-one|many mapped relation in Vaadin application. Did you ran into same issue? Are there any workarounds? It may be related to http://jira.codehaus.org/browse/GRAILS-5076 but I'm not sure. Thanks!
Michael
java.lang.RuntimeException: javax.servlet.ServletException: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:40)
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:135)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:101)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
...
Hi Michael,
I've not come across the problem you're describing while working with Vaadin in Grails. I have come across the same error in other applications though. Usually I've been able to fix them by changing the relationship to use eager loading instead of lazy loading, or accessing the collection that defines the relationship while the Hibernate session is still open.
Cheers,
Daniel
Hi Joe,
I just posted a simple Hello World application to the wiki here that uses the current version of the plugin. I've added some extra features to the plugin over the past week, and I'll be releasing it as soon as I get the chance to test it properly.
Cheers,
Daniel
Hi Daniel,
Thank you for the Vaadin Grails plugin and an overall great tutorial. It is really cool way to enable the developer to write Vaadin apps with Groovy. I do however have some problems using e.g. Button events within the Groovy/Vaadin setup. Is there anyway for you to extend the Hello World example and show how to use events within Groovy/Vaadin?
Kind regards,
Lars
Hi,
and foremost, thanks for providing the grails plugin.
However, I have a somewhat trivial newb question, which relates more to grails than Vaadin, though. How do you inject a grails service so that it can used in the Vaadin Application class?
A simple:
class MyApplication extends Application {
def someService
....
}
doesn't seem to work. someService is null when I call it. Any ideas how to solve this?
Nevermind, I found a solution for this. I'll share it, as this might save someone a minute or two.
You can get a handle to your service, for example, by using a factory class like this:
import org.codehaus.groovy.grails.commons.ApplicationHolder
class ServiceFactory {
def getSomeService() {
return this.getBean('someService')
}
private def getBean(beanName) {
return ApplicationHolder.getApplication().getMainContext().getBean(beanName)
}
}
Then you would use this class in a vaadin component, like this:
...
def serviceFactory = new ServiceFactory()
def service = serviceFactory.getSomeService()
...
Vaadin plugin is already working but I want to access grails controllers from the browser?
how can we access grails domain objects or controllers like the (index,list,etc..) ?
Hi Daniel,
How can we change the URL mapping on Vaadin application so that I could access grails controller in the browser.
Actually I could now access grails controllers and vaadin application in the browser by changing the url mapping
in VaadinGrailsPlugin.groovy from "/*" into "/VAADIN/*".
If I change it to other pattern like "/MainApp/*" , I get widgetset not loaded error. It only works on this pattern ("/VAADIN/*").
def servletMappings = webXml."servlet-mapping"
servletMappings[servletMappings.size() - 1] + {
"servlet-mapping" {
"servlet-name"("VaadinServlet")
"url-pattern"("/VAADIN/*")
}
}
Is there other way I could change this pattern ("/VAADIN/*") to access grails controller and access vaadin application
Thanks
nat nat
I used your modifications to the plugin as a starting point, with the following changes:
1. Update the web.xml generation to set the URL mapping from a config property, instead of always using "/*" (otherwise it won't play well with Grails controllers; it prevents you from ever seeing them).
2. Added another url mapping using the vaadin servlet to the URL pattern "/VAADIN/*". Without this, you can never reach the widgetset URLs and your Vaadin app won't run.
Hope that helps!
Drew McAuliffe: I used your modifications to the plugin as a starting point, with the following changes:
1. Update the web.xml generation to set the URL mapping from a config property, instead of always using "/*" (otherwise it won't play well with Grails controllers; it prevents you from ever seeing them).
2. Added another url mapping using the vaadin servlet to the URL pattern "/VAADIN/*". Without this, you can never reach the widgetset URLs and your Vaadin app won't run.Hope that helps!
What are the class I need to change or update? or do have a any code sample or a script we could follow?
Thanks.
Thank you very much Daniel,
VGrails framework uses your plugin in a very intensive way :)
http://vaadin.com/forum/-/message_boards/message/146536
Abiel
@West Java, Indonesia
nat-nat banzon:
Drew McAuliffe: I used your modifications to the plugin as a starting point, with the following changes:
1. Update the web.xml generation to set the URL mapping from a config property, instead of always using "/*" (otherwise it won't play well with Grails controllers; it prevents you from ever seeing them).
2. Added another url mapping using the vaadin servlet to the URL pattern "/VAADIN/*". Without this, you can never reach the widgetset URLs and your Vaadin app won't run.Hope that helps!
What are the class I need to change or update? or do have a any code sample or a script we could follow?
Thanks.
It's the VaadinGrailsPlugin.groovy file that has to change, which is what manipulates the web.xml. Here's a snippet of the main change, though I also modified the logging block under "getConfig" to show the currently configured urlValue.
def vaadinApplicationClass = config.applicationClass
def vaadinProductionMode = config.productionMode
def vaadinUrlPattern = config.urlPattern
def contextParams = webXml."context-param"
contextParams[contextParams.size() - 1] + {
"context-param" {
"description"("Vaadin production mode")
"param-name"("productionMode")
"param-value"(vaadinProductionMode)
}
}
def servlets = webXml."servlet"
servlets[servlets.size() - 1] + {
"servlet" {
"servlet-name"("VaadinServlet")
"servlet-class"("com.vaadin.terminal.gwt.server.GrailsAwareApplicationServlet")
"init-param" {
"description"("Vaadin application class to start")
"param-name"("application")
"param-value"(vaadinApplicationClass)
}
"load-on-startup"("1")
}
}
def servletMappings = webXml."servlet-mapping"
servletMappings[servletMappings.size() - 1] + {
"servlet-mapping" {
"servlet-name"("VaadinServlet")
"url-pattern"(vaadinUrlPattern)
}
"servlet-mapping" {
"servlet-name"("VaadinServlet")
"url-pattern"("/VAADIN/*")
}
}
Server running. Browse to http://localhost:8090/hello-vaadin
[groovyc] Compiling 1 source file to
C:\Java\test\GrailsTests\hello-vaadin\target\classes
[groovyc] Compiling 2 source files to
C:\Java\test\GrailsTests\hello-vaadin\target\classes
[delete] Deleting directory C:\Documents and
Settings\admin\.grails\1.2.1\projects\hello-vaadin\tomcat
2. When I load the page in browser, the page is sometimes unavailable
(error 503).
Maybe this has something to do with the first problem.
Has anyone seen the same problem?
======================
Hey Abiel,
Thanks for the feedback :) . I'm glad it's been useful for you. Congratulations on VGrails: it looks great!
Daniel
Hi All,
Based on Daniel's work, I've released a new (version 1.1) Grails Vaadin plugin. It now supports:
- Latest stable Vaadin version (6.3.3 at this time)
- Paths to your Vaadin UI other than the context root (e.g. http://www.somehost.com/myapp/vaadinUI)
- Per-environment configuration (Vaadin's 'production mode' = true for Grails production environment only. Can be overridden for any environment). Custom environments are also supported (e.g. 'beta', 'uat', etc)
A *huge* benefit to Grails 1.3 users is that because Grails 1.3 supports Groovy 1.7, which can use nested and anonymous inner classes, you can program all of your Vaadin UI in Groovy with natural Rich UI paradigms. For example, button listener registration and nested logic:
// Remove a contact from a list:
def removalCount = 0
contactRemovalButton = new Button("-", new Button.ClickListener() {
void buttonClick(ClickEvent event) {
contactList.removeItem(contactList.value)
//reference a non-final attribute inside an anonymous inner class!
removalCount++;
}
})
To install in your grails app:
> grails install-plugin vaadin
Happy coding!
Les Hazlewood
http://www.katasoft.com
HI,
I tried this plugin. I have a simple objective that I can be productive by writing my Vaadin code in groovy hence avoiding any restarts/redeploys. In theory I would like to have only the changed class reloaded. Just like how JVM hotswap works. But what I observed is that any changes to files in src/groovy trigger a complete container restart which is not the desired result. I would love it it works like Jrebel (zeroturnaround.com) which replaces only the changed artifacts. My groovy scripts are places in src/groovy. Am I doing anything wrong?
Thanks.
HI
I have the same behaviour. It's normal, cause to enable single class reloading in grails (like controllers or services) you need to write special artifact handling plugins.
As for me, this restart is very fast, so it doesn't harm development a lot
Another issue in grails: when you are using services in vaadin app. you need to restart application (?restartApplication) after service change (cause grails reloads changed service, but it can't update working vaadin apps)
In summury I can say that I feel very comfortable with vaadin in grails
Hi All!
Who can upgrade plugin to vaadin 6.4.6?
Thanks!
I am running the SimpleAddressBook Vaadin tutorial using a Grails application and the Grails Vaadin plugin. I have created a groovy file (SimpleAddressBook.groovy) containing the tutorial sample code with small modifications to the array initializers. There is a problem with filtering the table using the bottom column filters: it always returns 0 matches (no matter what value I use for the filter string). However if I rename SimpleAddressBook.groovy to SimpleAddressBook.java the filtering works fine.
Any ideas why is this happening?
I've changed VaadinGrailsPlugin.groovy like below and it works.
def vaadinApplicationClass = config.applicationClass
def vaadinProductionMode = config.productionMode
def vaadinGAEMode = config.googleAppEngineMode
def applicationServlet = vaadinGAEMode ? GAE_APPLICATION_SERVLET : APPLICATION_SERVLET
def contextParams = webXml."context-param"
contextParams[contextParams.size() - 1] + {
"context-param" {
"description"("Vaadin production mode")
"param-name"("productionMode")
"param-value"(vaadinProductionMode)
}
}
def servletName = "VaadinServlet"
def servlets = webXml."servlet"
servlets[servlets.size() - 1] + {
"servlet" {
"servlet-name"(servletName)
"servlet-class"(applicationServlet)
"init-param" {
"description"("Vaadin application class to start")
"param-name"("application")
"param-value"(vaadinApplicationClass)
}
"load-on-startup"("1")
}
}
def contextRelativePath = config.contextRelativePath ? config.contextRelativePath : "/";
if (!contextRelativePath.endsWith("deneme/")) {
contextRelativePath += "deneme/";
}
def servletMapping = contextRelativePath + "*"
def servletMappings = webXml."servlet-mapping"
servletMappings[servletMappings.size() - 1] + {
"servlet-mapping" {
"servlet-name"(servletName)
"url-pattern"("/deneme")
}
}
if (!contextRelativePath.equals("/")) {
//need to additionally specify the /VAADIN/* mapping (required by Vaadin):
servletMappings[servletMappings.size() - 1] + {
"servlet-mapping" {
"servlet-name"(servletName)
"url-pattern"("/main/*")
}
"servlet-mapping" {
"servlet-name"(servletName)
"url-pattern"("/VAADIN/*")
}
}
}
}
The Vaadin Grails plugin works great. The only serious limitation that I see is that it limits you to a single Vaadin app. Any serious web site will have multiple Vaadin apps targeting specific areas. For example, the travel agent might have an app managing all the trips available for customers and then another app is used by the customer to manage their specific trips.
Am I missing how to configure this with Vaadin.groovy config file?
If this is not possible, are there any plans to support this? I love Grails and Vaadin, but this is a serious limitation that I cannot live with unfortunately.
Thanks in advance,
Frik
If this is not possible, are there any plans to support this? I love Grails and Vaadin, but this is a serious limitation that I cannot live with unfortunately.
I know next to nothing about Grails, but as far as I understand it there should be no limitations from the Vaadin side. The Grails plugin is a community effort (the official roadmap is here), so patches are more than welcome :)
Agree - this is definitely not a Vaadin limitation. This is a limitation of the Vaadin plugin for grails.
If no one else has done the work already, I will definitely consider updating the plugin to support this.
Thanks for your response.
Kind regards,
Frik
Can everyone please vote to show how important it is to support multiple Vaadin applications on a single Grails server?
http://jira.codehaus.org/browse/GRAILSPLUGINS-1894
Michael Carl:
java.lang.RuntimeException: javax.servlet.ServletException: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
...
This is an old post, but didn't see an answer on here regarding this problem. I recently ran into this myself, and though, cause is unknown (something between Vaadin, Grails, and Hibernate - helpful, huh?), I was able to get around this by only showing relevant data fields in the container I was populating and ignoring those put in by GORM/Vaadin using setVisibleColumns().
Seems simple enough. Like I said, exact cause unknown, but this works in my case. Freakishly, this problem led me to start developing my Grails view layer in Zk (gasp!), but now I'm back to Vaadin and very, very relieved.
Chris
I need an answer to this problem too. I have many classes that have associations to other classes.
e.g.
Person has a Company.
I want to be able to display the Person instances with the name of the company in a Table. In other frameworks, I can use "dot notation". e.g. firstName, lastName, company.name, company.ticker, etc...
Furthermore the Company may have an Address. Therefore, I would want to display company.address.city, company.address.state, etc...
I may want to display this in a Table or a Form.
I cannot use "eager" loading. What can I do today to get lazy loading to work?
Robert La Ferla: I need an answer to this problem too. I have many classes that have associations to other classes.
e.g.
Person has a Company.
I want to be able to display the Person instances with the name of the company in a Table. In other frameworks, I can use "dot notation". e.g. firstName, lastName, company.name, company.ticker, etc...
Furthermore the Company may have an Address. Therefore, I would want to display company.address.city, company.address.state, etc...
I may want to display this in a Table or a Form.
I cannot use "eager" loading. What can I do today to get lazy loading to work?
JPA specification does not support lazy loading for detached entities, and Hibernate does not support it by design - EclipseLink does to some extent. This is further complicated by the fact that the only way to re-attach an entity to a session is to merge() it (or reload it from scratch based on the id etc).
When using the JPA-session-per-request pattern (as usual in web applications), in the next request from the UI your entities are not anymore attached to the old session, so lazy loading for them does not work. As you usually keep the restored entity instances in the application (in e.g. a Tomcat session), they are no longer valid for lazy loading upon the next request when using Hibernate.
Some frameworks - especially Web 1.0 style applications - can work with this because they never hold onto entity instances in memory but always reload them on every request. However, any system that does not do so will have problems with lazy loading when using Hibernate.
This is further complicated by the Hibernate "feature" that the session is invalidated when there is an exception, so using sessions that span many HTTP requests is not really an option either with Hibernate.
To summarize, I believe your options are to:
- disable lazy loading selectively or
- arrange for the entities/values to be re-loaded in each request (e.g. by not storing entity instances but only IDs) - how to do this and whether it is really doable depends on the application or
- check whether e.g. EclipseLink works better than Hibernate in your case
Suggestions for better alternatives would be welcome.
Hey Daniel,
Have you guys with Les considered adding scaffolding to the Vaadin Grails plugin?
I mean, is it on roadmap already?
I'm asking because I'm interested in contributing to the plugin in such way but don't want to duplicate the feature.
Speaking about contribution. Is there any specific condition to become commiter?
Regards,
topr
Commit question might be of general interest. Split the thread. The new thread can be found at http://vaadin.com/forum/-/message_boards/view_message/454319.
The Jira ticket that I raised originally to add support for multiple Vaadin applications using the Grails plugin has moved to: http://jira.grails.org/browse/GPVAADIN-2
As one can see that was raised about a year and a half ago, so I don't think that anyone has had a chance to look at it yet. I think the best way would be if we simply got commit rights or at least provided a patch that could be incorporated in the next release of the plugin.
On that note, does anyone know what the roadmap is for the plugin, if there is one?
Regards,
Fredrik
Hi Krish, have you found any solution for this problem?
Regards
krishvaadin kri krish: Server running. Browse to http://localhost:8090/hello-vaadin
[groovyc] Compiling 1 source file to
C:\Java\test\GrailsTests\hello-vaadin\target\classes
[groovyc] Compiling 2 source files to
C:\Java\test\GrailsTests\hello-vaadin\target\classes
[delete] Deleting directory C:\Documents and
Settings\admin\.grails\1.2.1\projects\hello-vaadin\tomcat
2. When I load the page in browser, the page is sometimes unavailable
(error 503).
Maybe this has something to do with the first problem.
Has anyone seen the same problem?
======================
Is the Grails Vaadin plugin still maintained?
If so, or even if not, where is the source repository located so that others might fork it?
Thanks
Hi Kirk,
here is the JIRA project for this plugin: http://jira.grails.org/browse/GPVAADIN It seems there are only new requests but not that much of done work... :-/ I have asked to upgrade the plugin to the latest version of Vaadin (but I am not sure if that is going to happen).
I am trying to develop some CRUDS with Vaadin grails plugin but i am having some problems.
Is there any tutorial? working sample?
I am having problems with data on demand because i have some tables with more than 500K records and when i use
Person.list().each { container.addBean it }
to populate the container, the entire application collapse...
can someone give me a hand with that?
thanks!