How to detect that a controller has been called by g:include tag lib?
In order to send appropriate response, I need to detect whether the controller action has been requested by a classic HTTP GET request, an AJAX request or a g:include tag lib.
For instance, considering the following snippet code:
class CommunityController {
def show = {
def users = getUsers()
if (/* WHAT IS THE CODE HERE??? */) //g:include request => render 'show' template only
render template:'show', model=[users]
else if (request.xhr) //Ajax => we send JSON content
render users as JSON
else //Classic request => we render 'show' G开发者_开发技巧SP page
[users]
}
}
...how can I detect that the action has been called via a g:include tag lib?
Thank you.
You can test it like this:
import org.springframework.web.util.WebUtils
if (request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)) {
// request was included
}
精彩评论