grails

Mailing Exception logs in a live Grails webapp

I'd like my Grails web-app to send an e-mail for each exception that reaches the end-user. Basically I'm looking for a elegant way to achieve something equivalent to: try { // ... all logic/db-access/etc required to render the page is executed here ... } catch (Exception e) { sendmail("[email protected]", "An exce...

Legacy mapping in Grails/GORM: One domain class and two tables in a 1:N-relationship

Let's say I have two tables employee and salary with a 1:N relationship (one salary can be associated with many employees). In plain SQL the tables would be joined with: SELECT e.id, e.name, s.salary FROM employee e, salary s WHERE s.id = e.salary_id AND e.id = 12345; Assuming the following GORM-powered domain class how do I map the ...

Config.groovy in Grails: environments.production.grails.serverURL

Can anyone give a specific example of when the following setting in Config.groovy is used? // set per-environment serverURL stem for creating absolute links environments { production { grails.serverURL = "http://www.changeme.com" } ... } What I am looking for is a use-case where not changing the above setting will ...

Problem with ImageTools plugin in Grails

Hi guys, i have a grails project with an Image Domain Class and Controller. I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded. My Image-Domain-Class: class Image { byte[] data //String name byte[] thumbnail static constraints = { //name() data() } } ...

Add a field to a Grails Domain Class?

I would like to add a field to an existing domain class. I do not want to lose my view files however as I know will happen if i run generate-all. Is there another way I can update the mapping etc? ...

Config.groovy in Grails: grails.views.default.codec - why base64?

The Config.groovy setting "grails.views.default.codec" specifies the default codec used to encode data with ${...}. This config setting can take any of the values "none", "html" and "base64". I understand the reason to why one would set them to "none" (no filtering required) or "html" (to avoid XSS-attacks), but why would anyone like ...

Case insensitive search in grails

I am developing grails application which uses file searching.For that I wrote the following code. This code works and it is gives the results with case sensitive.But I want to search files without case sensitive. def criteria = FileDomain.createCriteria() def results = criteria { and { like('user', User.findById(session?.user...

Iframe is not working in Firefox and IE

I am developing a application in grails which uses lot of ajax.In one part I used the following code : <iframe id="hidden-upload-frame" style="border:none;height:25px;width:100%;" onload="${remoteFunction(action: 'list', controller: 'file', update: [success: 'fileDomain', failure: 'fileDomain'])}"> </iframe> <div id="fileDomain"> </di...

Grails/GORM default fetch strategy: When to set fetchMode to "eager"? (eager vs. lazy)

What are some general guidelines on when to set fetchMode to "eager" in a domain class? Pros and cons of fetchMode "eager" vs. the default "lazy"? Please include some specific examples/use-cases showing when to use "eager" (fetchMode=eager), and when not to (fetchMode=lazy). ...

Grails/GORM: The meaning of belongsTo in 1:N relationships

In an ordinary one-to-many mapping the "one"-side is the owner of the association. Why would anyone use the belongsTo-mapping for such a mapping? Am I missing some side-effect of specifying belongsTo? In other words: what are the effects of specifying a belongsTo-mapping in GORM vs. not specifying it? ...

Doing a run-around of existing application to make database changes, good idea?

We have an existing "legacy" app written in C++/powerbuilder running on Unix with it's own Sybase databases. For complex organizational(existing apps have to go through lot of red-tape to be modified) and code reasons(no re-factoring has been done in yrs so the code is spaghetti), so it's difficult to get modifications done to this appl...

Grails Eclipse plugin

Hi, I've seen various posts on SO criticising the Eclipse Grails plugin, and am wondering if anyone has found a way to work productively with Grails within Eclipse? I had a look at the Grails plugin page, and the information there doesn't look very promising, particularly the conflicting advice regarding the 'Disable Groovy Compiler Ge...

What is the correct target for the JAVA_HOME envrionment variable for a Linux OpenJDK debian-based distribution?

Folks In Windows, JAVA_HOME must point to the JDK installation folder (so that JAVA_HOME/bin contains all executables and JAVA_HOME/libs contains all default jar libraries). If I download Sun's JDK bundle and installs it in Linux, it is the same procedure. However, I need to use Kubuntu's default OpenJDK package. The problem is that a...

Identifying ajax request or browser request in grails controller

Hi I am developing a grails application which uses lot of ajax.If the request is ajax call then it should give response(this part is working), however if I type in the URL in the browser it should take me to the home/index page instead of the requested page.Below is the sample gsp code for ajax call. <g:remoteFunction action="list" con...

Unsafe use of user-supplied GString:s in Groovy/Grails

The GString concept in Groovy is pretty powerful (see http://groovy.codehaus.org/Strings+and+GString). GStrings let you do things like: world = "World" println "Hello ${world}" # Output: Hello World println "1+2 = ${1+2}" # Output: 1+2 = 3 println "${System.exit(-1)}" # Program terminated I'm trying to figure out if using Groovy GStr...

How to access domain classes from src/java in GRAILS?

Hi there! How can I access or better pass on a bunch of domain classes from a controller in Grails to a quite simple java program residing in src/java within the grails tree? I always get a ClassNotFoundException for the domain classes, regardless in which package I put them in. There's no auto-completion pointing to the domain classes ...

grails default constraints

Hi, Assume I have a Grails domain object like this: class Todo { String name String priority String status static constraints = { name(blank: false) priority() } } What are the default constraints on a field if: It's listed in the constraints block without any actual contraints, e.g. priori...

How to establish a Hibernate session within a grails script

The following grails script: // Import.groovy includeTargets << grailsScript("Bootstrap") target(main: "Import some data...") { depends(bootstrap) def Channel = grailsApp.classLoader.loadClass("content.Channel") def c // works: saving a valid Channel succeeds c = Channel.newInstance(title:"A Channel", slug:"a-c...

Groovy GDK equivalent of Apache Commons StringUtils.capitalize(str) or Perl's ucfirst(str)

Yes/no-question: Is there a Groovy GDK function to capitalize the first character of a string? I'm looking for a Groovy equivalent of Perl's ucfirst(..) or Apache Commons StringUtils.capitalize(str) (the latter capitalizes the first letter of all words in the input string). I'm currently coding this by hand using .. str = str[0].toUpp...

Valid Java code that is NOT valid Groovy code?

Most Java code is also syntactically valid Groovy code. However, there are a few exceptions which leads me to my question: Which constructs/features in Java are syntactically invalid in Groovy? Please provide concrete examples of Java code (Java 1.6) that is NOT valid Groovy code (Groovy 1.6). Update: So far we've got five examples o...