开发者

How to detect that a controller has been called by g:include tag lib?

开发者 https://www.devze.com 2023-01-20 15:56 出处:网络
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.

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号