What is the Difference between render and return render in Grails -
what difference between following in grails:
render xyz
return render xyz
i have return render xyz in controller action , controller action gets called multiple times in ie. wondering if return render culprit. works fine in local intellij tomcat app server fails in production weblogic server.
render void method, has no return value, , returning return value equivalent returning null. groovy treats returning nothing (e.g. simple return statement) , returning null equivalent, , return value of controller actions ignored unless value map since "result" of controller action isn't that's returned, rather done.
specifically means can issue redirect, forward, or render call, , these trigger expected responses. if return map however, it's inferred model map used render gsp same name action in controller's views folder, e.g. bar action in foocontroller renders grails-app/views/foo/bar.gsp.
if have logic branch, e.g. in save action successful result followed redirect show action, failure result results in re-rendering of edit page previous values , errors shown, can use simple if/else, e.g.
if (successful) { redirect ... } else { render ... } or can return early, e.g.
if (successful) { redirect ... return } render ... so you're seeing combining 2 lines one:
if (successful) { return redirect ... } render ... it's bit of hack since implies you're returning redirect (or other void method) returns, you're returning nothing. works , it's valid, preference keep return statement on own line since there's no ambiguity what's happening.
Comments
Post a Comment