grails-2.0

Parameters with new where queries in Grails 2.0

半城伤御伤魂 提交于 2019-12-13 13:18:42
问题 Is it possible to use parameters when defining a where query in Grails 2.0? For example: def query = Book.where { id == it } Book sub = query.find(5) I tried running that code, but it throws a MissingMethodException on the call to find. I also tried defining a variable before it, but it doesn't seem to work (as find returns null, even though I know it exists). Long someId = 5 def query = Book.where { id == someId } Book sub = query.find() Any tricks? Being able to dynamically change the

Using GORM efficiently to retrieve join data - Grails 2.3

寵の児 提交于 2019-12-13 12:50:52
问题 I have User, and Follow Domain class that construct the Follower, Following relationship like Twitter. When my User visits another User's page, and click on their Follower list. I pop-up the list of the visited person's follower list, and then show a button in front of it that is labeled "Follow" or "Unfollow" depending on if you already following that person. So I do it the following way, but I'm not sure if this is efficient or maybe there is a better way of doing it. In order to make it

Grails + GORM: What is the default equals() implementation in GORM?

强颜欢笑 提交于 2019-12-13 11:36:01
问题 When I do domainObj1 == domainObj2 in Grails are the objects compared by ID? If not, how are they compared? 回答1: First, you need to understand that GORM/Grails doesn't do anything special when it comes to equals() . Unless you implement your own equals() on your domain class it will default to the Java/Groovy implementation. Which by default means the variables must point to the same instance. Now, what gets slightly confusing is Hibernate. Hibernate uses an identity map (the first-level

ClientAbortException: java.io.IOException: Broken pipe

可紊 提交于 2019-12-13 05:15:03
问题 I have the following code to send a jpg image on the outputstream in Grails. I use this block inside a cache headers generate{...} statement. def imageByteArray = // some image byte [] response.setContentType("image/jpeg") response.setHeader("Content-disposition", "filename=\"${imageName}${imageExtension}\"") response.setContentLength(imageByteArray.size()) def outputStream = null try { outputStream = response.outputStream outputStream << imageByteArray } catch (IOException e){ log.error(

grails - multiple database for multiple client but one source

空扰寡人 提交于 2019-12-13 04:33:07
问题 how to use multiple database for multiple client but one source. is there any way to change DataSources.groovy file? 回答1: Yes, this is possible. Just copy your dataSource at the top of your dataSource file and rename it (eg datasource2). Then copy the dataSource in the development, test and production. Rename the new dataSources with the same name. Now you are ready to use your dataSource2 with the same way as you use dataSource. class MySercise { def dataSource2 def myMethod() { def sql =

Upgrade to Grails 2.0: /index.gsp not found

五迷三道 提交于 2019-12-13 02:36:16
问题 I have upgraded from Grails 1.3.7 to 2.0.0.RC1: After sorting out a lot of issues with depdendencies I have finally managed to start my Grails application but when browsing to URL it tell me I receive the following: GroovyPagesServlet: "/index.gsp" not found It worked perfectly before... where is it looking for it? Thanks Jonas 回答1: ok, I figured it out. The above syntax in UrlMappings.groovy does not work. It must be: "/" { controller = "user" action = "login" } 回答2: As I add SecurityFilters

Grails 2.1.1 - How to develop a plugin with an AstTransformer?

只愿长相守 提交于 2019-12-12 15:15:35
问题 I want to replace the auto injected log object, which is of type org.apache.commons.logging.Log with an object of type org.slf4j.Logger , so that I can use it properly with Logback. Therefore I need to create a ...Transformer class (written in Java) - that's what I got from Graeme Rocher over at the "grails-user" mailing list. I'm also aware that I have to pack this ...Transformer class within a plugin and make it a *.jar archive which I can load within the lib/ folder of the plugin. But I

Geb Firefox Driver: why my test runs twice?

别等时光非礼了梦想. 提交于 2019-12-12 14:25:10
问题 Sorry for all this code, but I don't have a clue what's making my issue, so here it goes. I configured the geb plugin to run functional tests with JUnit. So I have in my buildConfig.groovy : def seleniumVersion = "2.29.0" def gebVersion = "0.7.0" dependencies { // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg. // runtime 'mysql:mysql-connector-java:5.1.5' provided('com.oracle:oracle:11.1.0.7.0') provided('com.oracle:i18n:10.2.0.5') test (

How to externalise Maven credentials in Grails 2.4

ⅰ亾dé卋堺 提交于 2019-12-12 07:35:19
问题 I'm trying to migrate from using Ivy to using the Aether resolver in a Grails 2.4 project. The issue I am having is in relation to externalising the credentials. Info related to this can be found in the Grails manual here: http://grails.org/doc/latest/guide/conf.html#dependencyRepositories There doesn't seem to be a documented way to externalise the credentials for using Maven the way you could with Ivy. With Ivy I could place something like this into my .grails/settings.groovy file: grails

How to display different flash.message in different style in GSP page

浪尽此生 提交于 2019-12-12 03:57:48
问题 I have to display different messages using flash.message, some of them have to be in different color, So How to distinguish the flash.message and display them in different color in GSP 回答1: the view page code to view error and suces msg in different style <g:if test="${flash.message}"> <div class="message" role="status" style="font-size: medium;color: green;">${flash.message}</div> </g:if> <g:if test="${flash.warning}"> <div class="message_error" style="font-size: medium;color: red;">${flash