Groovy console can’t “remember” any variables – always says “unknown property”

This is standard behavior in the Groovy shell, not peculiar to the Grails shell. You probably don’t want to def the variable. See the following: ~ $ groovysh Groovy Shell (2.3.4, JVM: 1.7.0_45) Type ‘:help’ or ‘:h’ for help. ——————————————————————————- groovy:000> def x = 42 ===> 42 groovy:000> x Unknown property: x groovy:000> y = … Read more

Inject grails application configuration into service

The grailsApplication object is available within services, allowing this: package example import com.example.ExampleApiClient; class ExampleService { def grailsApplication def relevantMethod() { def client = new ExampleApiClient( grailsApplication.config.apiCredentials.baseUrl grailsApplication.config.apiCredentials.username, grailsApplication.config.apiCredentials.password ) return client.action(); } }

What does the question mark mean in GSP/Grails?

It’s the “Safe Navigation Operator”, which is a Groovy feature that concisely avoids null pointer exceptions. See http://docs.groovy-lang.org/latest/html/documentation/index.html#_safe_navigation_operator In this case, if phoneInstance is null, then it doesn’t try to get the name property and cause a NPE – it just sets the value of the field tag to null.

Overriding grails.views.default.codec=’html’ config back to ‘none’

To summarize the various levels at which the codec can be applied: Set Config.groovy’s grails.views.default.codec=”html” to get HTML escaping by default on all ${expressions} in the application. Then when you want to default a whole page back to none, use the directive: <%@page defaultCodec=”none” %> or <%@ defaultCodec=”none” %> To disable HTML encoding for one … Read more

How can i set default value in grails domain class

This will be possible in 2.2 which should be released this week or next. See http://jira.grails.org/browse/GRAILS-5520 for the relevant feature request. The syntax will be static mapping = { name defaultValue: “‘Cash'” } For now you’ll need to do what you’re doing – set the value as the default value of the field. You can … Read more

Difference between findAll, getAll and list in Grails

getAll is an enhanced version of get that takes multiple ids and returns a List of instances. The list size will be the same as the number of provided ids; any misses will result in a null at that slot. See http://grails.org/doc/latest/ref/Domain%20Classes/getAll.html findAll lets you use HQL queries and supports pagination, but they’re not limited … Read more