Question

remoteLink is used to call server handler in Grails project like below. I can place blockUi method in onLoading to make remote invoke friendly. If there is a little remoteLink, I can do this for every remoteLink. But if there are a lot of remoteLink, repeating this is not a good practice as my imagination.

I want to use GSP tags. Is there any method like an interceptor for remoteLink ajax loading event to do it without repeating? If there is, then it will be better if some remoteLink can be excluded from blockUi by placing a tag like: except='true'

Thanks a lot for help!

<g:remoteLink action="show"
          id="1"
          update="success"
          onLoading="blockUi()"
          onComplete="hideProgress()">Show Book 1</g:remoteLink>
Was it helpful?

Solution

You can create your own TagLib and call remoteLink with your onLoading by default.

class AjaxTagLib {
  static namespace = "my" //define a namespace to not conflict with g

  def remoteLink = { attrs ->
    //default onLoading attribute
    if(!attrs.onLoading) {
      attrs.onLoading = "blockUi()"
    }
    g.remoteLink(attrs)
  }
}

Then you can use that instad of g.remoteLink:

<my:remoteLink action="show" id="1" update="success">Show Book 1</my:remoteLink>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top