How to determine that the controller was called by g: include tag lib?

To send the appropriate response, I need to determine if the controller action was requested using the classic HTTP GET request, AJAX request, or g: include tag lib .

For example, given 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' GSP page
      [users]
  }
}

... how can I detect that the action was invoked through g: include tag lib?

Thank.

+3
source share
1 answer

You can check it as follows:

import org.springframework.web.util.WebUtils

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

Source: https://habr.com/ru/post/1770330/


All Articles