grails

How to find a user's home directory on linux or unix?

How do I find the home directory of an arbitrary user from within Grails? On Linux it's often /home/user. However, on some OS's, like OpenSolaris for example, the path is /export/home/user. ...

uploaded files - database vs filesystem, when using Grails and MySQL

I know this is something of a "classic question", but does the mysql/grails (deployed on Tomcat) put a new spin on considering how to approach storage of user's uploaded files. I like using the database for everything (simpler architecture, scaling is just scaling the database). But using the filesystem means we don't lard up mysql w...

Defining controller accessible variables from filters in Grails

I'm writing a small webapp in Grails, and to make sure all users are authenticated I'm using the following filter: class LoginFilters { static filters = { loginCheck(controller:'*', action:'*') { before = { if (session.user_id) { request.user = User.get(session.user_id) } else if (!actionName.equals...

Specify order of fields in DDL generated from GORM classes?

I use GORM to generate my database's DDL from groovy classes. Which is great. However, the order of fields in the generated SQL is not the same as the order of fields in the class. For example, if I create the class class Person { String firstName String lastName String address String email } the following SQL is generated ...

How to get started with GRAILS on an existing J2EE app?

I'm new to grails. I'd like to give it a whirl by implementing a new feature or two into an existing J2EE application. The current J2EE app is a fairly standard Spring MVC/Hibernate app running on Tomcat. Looking through the documentation, it looks like I should be able to leverage all of the current business logic that's written in J...

Setting Grails domain id in Bootstrap.groovy

Is it possible to explicitly set the id of a domain object in Grails' Bootstrap.groovy (or anywhere, for that matter)? I've tried the following: new Foo(id: 1234, name: "My Foo").save() and: def foo = new Foo() foo.id = 1234 foo.name = "My Foo" foo.save() But in both cases, when I print out the results of Foo.list() at runtime, I ...

Accessing the model from a layout view in Grails

I'm using the layout support (sitemesh) in Grails which works fine. I'd like to adjust my layout to have it depend on whether or not a user is logged in or not. My grails-app/views/layouts/main.gsp contains the following code: <g:if test="${user}"> Username: ${user.username} </g:if> However, it appears as if the layout-GSP:s are un...

Why does Grails need Xerces?

We had in a grails-project problems with different XML-libraries clashing. The solution was to delete xercesImpl.jar from $GRAILS_HOME/lib. Grails does work well without it. So my question is, why was the xerces-library in the grails-distribution in the first place? ...

Hands-on study plan for learning Grails

I'm a Java developer trying to learn Grails, and I'd like to get exposure to as many parts of the Grails framework as possible. Preferably doing so by solving small real-world problems using the "Grails way to do it" (DRY, convention-over-configuration, and so on). Three example could be: Learn about GORM by creating a few classes (sa...

How to render 'how long ago something happened' using Groovy or Grails?

I would like a method/closure which works like this println TimeDifference.format( System.currentMilliSeconds()-1000*60*60*24*7*6 ) and prints 1 month, 3 weeks, 2 days, 45 hours and 3 minutes ago. Is there an off the shelf solution for this? ...

Using external log4j.properties file with Grails

What's the best way to use an external log4j.properties file within Grails? I'd like to use the traditional log4j.properties format rather than a log4j.groovy style configuration. I'm also curious if the external configuration will play nicely with the log4j.properties file that's created by grails war and put into the war file. If I re...

Limiting no of outputs in Hibernate query

I have a hibernate query in grails Book.findAllByRating(4) In the above query i want only 5 number of outputs.How do I limit the output to 5? ...

Defining default sort-order in Grails/GORM

Let's say I have definied a User object using GORM. Each user can have zero or more Login:s. Each Login has a timestamp. When retrieving user.logins I want the logins to be sorted based on the value of login.date. What is the correct Grails way to achieve this? Example: I want the following code to list all the user's logins in ascendin...

Storing Grails/GORM domain objects in the session - why not?

I'm learning Grails/GORM and as I've understood it the current best practice is not to store domain objects in the session (see http://jira.codehaus.org/browse/GRAILS-978 for a potential fix). The workaround is simple; simply store the reference id for the domain object in the session, and then re-retrieve the object using on the next r...

using junit 4 in grails

I'd like to use some JUnit 4 functionality in my grails testing, but currently grails tests run under JUnit 3. JUnit 4 can be used from groovy but replacing the JUnit jar within grails with a JUnit 4 one doesn't seem to enable the functionality I'm looking for. Anyone know how I can get grails to run my tests with junit 4? ...

Is there a Python equivalent of Groovy/Grails for Java

I'm thinking of something like Jython/Jango? Does this exist? Or does Jython allow you to do everything-Python in Java including Django (I'm not sure how Jython differs from Python)? ...

How popular is Groovy/Grails in the corporate world?

Are there any figures for its adoption in corporate environments? Does anyone know of large corporations that have adopted it for projects? ...

Reading the g:datePicker-value in Grails without using the "new Object(params)"-method

Let's say I have a datePicker called "foobar": <g:datePicker name="foobar" value="${new Date()}" precision="day" /> How do I read the submitted value of this date-picker? One way which works but has some unwanted side-effects is the following: def newObject = new SomeClassName(params) println "value=" + newObject.foobar This way o...

What are your favorite Grails debugging tricks?

Grails can be a bit of a bear to debug with its long stack dumps. Getting to the source of the problem can be tricky. I've gotten burned a few times in the BootStrap.groovy doing "def foo = new Foo(a: a, b: b).save()", for example. What are your favorite tricks for debugging Grails apps? ...

Interactively Run code against Grails Runtime Environment

I am working on some code to load some bootstrapping data into my Grails app. Something is not working with one of the classes I am trying to create, so it would be very convenient to be able to run that code interactively against the grails runtime environment and I am wondering if there is a way to do that. I know about the Grails ...