grails-2.0

Grails 2.4.4 DataSource “create-drop” fails to drop all tables having FKs

半腔热情 提交于 2019-12-11 09:28:08
问题 Using Grails 2.4.4, and have ported my domain classes from 2.2.0. There's a problem I am facing w.r.t "create-drop" config of DataSource, using MySQL as the datasource. Whenever I issue a grails stop-app command, out of total 35 tables, 22 tables are left in the schema. After enabling debug mode for Hibernate classes, and at the end of the stop-app process, it was generating drop table if exists <tablename> for all 35 tables, but no error/confirmation was there in the logs whether the drop

Grails 2.3.3 namespaced controller render view

匆匆过客 提交于 2019-12-11 04:38:54
问题 For Grails 2.3.3, it allows same name controller in different package with namespaced controller according to http://grails.org/doc/latest/guide/theWebLayer.html#namespacedControllers So we have package like this: /admin/FooController /public/FooController To keep consistent we want the view package like this: /views/admin/foo/... /views/public/foo/... However, in the FooController action, if you don't hard code the render method. It will find the view in the /views/foo/index.... It seems it

How to store result of quartz job in session?

邮差的信 提交于 2019-12-11 04:18:52
问题 I have installed Quartz plugin in my Grails 2.1 application. Every 5 minutes one job is triggered that will calculate some numbers. The numbers are being shown on the side bar of every page. The calculated results will change frequently and my goal is when users refresh their screen they can see the new result on their sidebar. Right now my approach is to send ajax call to a controller and grab the result from the database and render it on the screen. Is there any way to store (cache) the

Grails 2.3 - New Sample Project not working

只愿长相守 提交于 2019-12-11 03:56:33
问题 i created a new grails 2.3 sample project. It is giving error while refresh-dependencies or run-app Loading Grails 2.3.0.M1 | Configuring classpath | Error org.sonatype.aether.collection.DependencyCollectionException: Failed to collect dependencies for [xalan:serializer:jar:2.7.1 (compile), org.grails:grails-bootstrap:jar:2.3.0.M1 (compile), org.grails:grails-scripts:jar:2.3.0.M1 (compile), org.grails.plugins:tomcat:zip:7.0.39 (compile)] | Error at org.sonatype.aether.impl.internal

grails 2.3: tests not recognized by test-app

强颜欢笑 提交于 2019-12-10 21:06:09
问题 I am playing with the recently released grails 2.3.0. Unfortunately, test-app is not recognizing tests. Here is what I did to produce the problem. First, make a new app and create a controller: $ grails create-app firstApp $ cd firstApp/ $ grails create-controller foo I got the following files from creating the controller foo: | Created file grails-app/controllers/firstapp/FooController.groovy | Created file grails-app/views/foo | Created file test/unit/firstapp/FooControllerSpec.groovy Then,

How to avoid loss of DB when changing Grails domain class in development

坚强是说给别人听的谎言 提交于 2019-12-10 18:17:27
问题 One of the advantages of Grails 2.0 is that you can change domain classes in development without needing to restart the application server. This works, however when I change domain classes I lose all my bootstrap data, which basically defeats the purpose. I'm using the default h2 database. What is the best way to get around this? Do I have to go to an external DB like Postgres? 回答1: The default DataSource.groovy in a newly-created Grails 2 app has environments { development { dataSource {

How to mock a service in grails TagLib unit test

倾然丶 夕夏残阳落幕 提交于 2019-12-10 17:38:34
问题 I have TagLib, Service and TestCase as follows How to mock a service in a taglib to get expected result from service TagLib: class SampleTagLib { static namespace = "sample" def baseService def writeName = { attrs, body -> def result = baseService.findAttributeValue(attrs.something) if(result) out << body() } } Service: class BaseService { def findAttributeValue(arg1) { return false } } TagLibUnitTestCase: import spock.lang.* import grails.plugin.spock.* import org.junit.* import grails.test

How to implement Self-Referencing Relationships in Grails?

落花浮王杯 提交于 2019-12-10 17:34:59
问题 Given the following User class: class User { String name static hasMany = [friends: User] } I want that a User can have many friends which are instances of the user domain class. How do I have to implement the friend relationship of a user? 回答1: 1. How Do you Define the relathionship class User { static hasMany = [ friends: User ] static mappedBy = [ friends: 'friends' ] //this how you refer to it using GORM as well as Database String name String toString() { name } def static constrains () {

How to exclude specific keywords from UrlMapping in Grails?

心已入冬 提交于 2019-12-10 14:49:11
问题 I use the following url mapping in Grails: "/$id"{ controller = "user" action = "show" } to map urls like mydomain.com/someusername How do I attach constrains to the url mapping to exclude keywords like "login", "logout",... I.e., mydomain.com/someusername should route to mydomain.com/user/show/someusername, mydomain.com/login should not route to mydomain.com/user/show/login. 回答1: You can use contrainsts for this mapping: "/$id"{ controller = "user" action = "show" constraints { //add a

Grails UrlMapping Redirect to keep DRY

半世苍凉 提交于 2019-12-10 12:52:36
问题 I am working with Grails 2.1.1 and would like to add a handful of customized URLs that map to Controller Actions. I can do that, but the original mapping still works. For example, I created a mapping add-property-to-directory in my UrlMappings as follows: class UrlMappings { static mappings = { "/add-property-to-directory"(controller: "property", action: "create") "/$controller/$action?/$id?"{ constraints { // apply constraints here } } "/"(view:"/index") "500"(view:'/error') } } Now, I can