如何检测g:include标签lib调用控制器?

时间:2010-10-19 14:49:06

标签: grails gsp

为了发送适当的响应,我需要检测经典HTTP GET请求,AJAX请求或g:include标记库是否已请求控制器操作。

例如,考虑以下代码段:

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' GSP page
      [users]
  }
}

...如何通过g:include标签lib?

检测到该动作已被调用

谢谢。

1 个答案:

答案 0 :(得分:5)

你可以这样测试:

import org.springframework.web.util.WebUtils

if (request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)) {
    // request was included
}