How do I call a Grails service from a gsp?

Best to use the tag library because creating a service instance directly in the view via the class loader WILL NOT autowire other services declared that may live in the service you are trying to use. Using the tag library you will have auto-wiring of those services. In your gsp view <g:customTag param1=”$modelObjec” param2=”someString” /> … Read more

grails-app/utils dir

the grails-app/utils/ directory is where items like Codecs go. I’m not sure what else goes there, but you can include other classes there and they will be included within the Application EDIT: The grails-app/utils/ directory is meant for “Grails specific utilities” (Artefacts, GrailsClasses, etc.) Jeff Brown(Core member of the Grails development team) responded to a … Read more

Groovy: isn’t there a stringToMap out of the box?

You might want to try a few of your scenarios using evaluate, it might do what you are looking for. def stringMap = “[‘a’:2,’b’:4]” def map = evaluate(stringMap) assert map.a == 2 assert map.b == 4 def stringMapNested = “[‘foo’:’bar’, baz:[‘alpha’:’beta’]]” def map2 = evaluate(stringMapNested) assert map2.foo == “bar” assert map2.baz.alpha == “beta”

Grails – getting a message value from controller

Inside a controller or a taglib, you can use the following : g.message(code: ‘some.message’) However, inside domain classes or services, you need to inject messageSource and call getMessage() method from Sping class AbstractMessageSource. This snippet shows you how to do that: import org.springframework.context.i18n.LocaleContextHolder as LCH … class MyServiceOrMyDomain { def messageSource … messageSource.getMessage(code, msgArgs, defaultMsg, … Read more

Retrieving a list of GORM persistent properties for a domain

Try this: import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass … def d = new DefaultGrailsDomainClass(YourDomain.class) d.persistentProperties Here’s a link to the Grails API for GrailsDomainClass (it’s a link to an older version; I couldn’t find a newer one after some quick searches). It’s got a getPersistentProperties() (used in the code snippet above). You can traverse the API documentation to see … Read more

FileUpload with JAX-RS

On Server Side you can use something like this @POST @Path(“/fileupload”) //Your Path or URL to call this service @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile( @DefaultValue(“true”) @FormDataParam(“enabled”) boolean enabled, @FormDataParam(“file”) InputStream uploadedInputStream, @FormDataParam(“file”) FormDataContentDisposition fileDetail) { //Your local disk path where you want to store the file String uploadedFileLocation = “D://uploadedFiles/” + fileDetail.getFileName(); System.out.println(uploadedFileLocation); // save it … Read more

Increase timeout for gradle to get a maven dependency

The feature was added in Gradle here: https://github.com/gradle/gradle/pull/3041 You can increase the timeout with 2 properties: ./gradlew build -Dhttp.socketTimeout=60000 -Dhttp.connectionTimeout=60000 As commented by Sue C, If you are using gradle 4.10.2 or later version use following properties: ./gradlew build -Dorg.gradle.internal.http.socketTimeout=60000 -Dorg.gradle.internal.http.connectionTimeout=60000

Detecting the platform (Window or Linux) by Groovy/Grails

System.properties[‘os.name’] will return the name of the OS, e.g. “Windows XP”. So if you want to figure out whether you’re running on Windows or not, you could do something like: if (System.properties[‘os.name’].toLowerCase().contains(‘windows’)) { println “it’s Windows” } else { println “it’s not Windows” } Alternatively, org.apache.commons.lang.SystemUtils (from the Apache commons-lang project) exposes some boolean constants … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)