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

Why should grails actions be declared as methods instead of closures and what difference does it make?

The answer is here From above link Leveraging methods instead of Closure properties has some advantages: Memory efficient Allow use of stateless controllers (singleton scope) You can override actions from subclasses and call the overridden superclass method with super.actionName() Methods can be intercepted with standard proxying mechanisms, something that is complicated to do with Closures … Read more

How to access Grails configuration in Grails 2.0?

If you need it in an artifact that supports dependency injection, simply inject grailsApplication class MyController { def grailsApplication def myAction = { def bar = grailsApplication.config.my.property } } If you need it in a bean in, say, src/groovy or src/java, wire it up using conf/spring/resources.groovy // src/groovy/com/example/MyBean.groovy class MyBean { def grailsApplication def foo() … Read more

Grails3 file upload maxFileSize limit

Grails 3, Grails 4 and Grails 5 The solution is to set maxFileSize and maxRequestSize limits inside your application.yml file (usually placed inside grails-app/conf/). Be sure to have something like this: grails: controllers: upload: maxFileSize: 2000000 maxRequestSize: 2000000 Replace 2000000 with the number of max bytes you want for a file upload and for the … Read more

Accessing the raw body of a PUT or POST request

It is possible by overriding the HttpServletRequest in a Servlet Filter. You need to implement a HttpServletRequestWrapper that stores the request body: src/java/grails/util/http/MultiReadHttpServletRequest.java package grails.util.http; import org.apache.commons.io.IOUtils; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.ServletInputStream; import java.io.*; import java.util.concurrent.atomic.AtomicBoolean; public class MultiReadHttpServletRequest extends HttpServletRequestWrapper { private byte[] body; public MultiReadHttpServletRequest(HttpServletRequest httpServletRequest) { super(httpServletRequest); // Read the request … Read more

Grails unable to install plugin

The repository changed and it’s causing problem for older Grails versions. See my answer at: Grails Url shortener plugin not getting installed : Please use mavenRepo “https://repo.grails.org/grails/plugins” As a repository definition. http://grails.1312388.n4.nabble.com/Grails-central-repo-seemingly-missing-plugin-versions-td4658720.html