Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any reason to use JavaScript library plugins in grails that expose the given library via TagLibs instead of just using it directly?

If you search the grails plugin site, you'll find lots of plugins for JQuery and other JavaScript libraries. Most of these expose the given JavaScript library functionality through Grails TagLibs. Is this really an advantage, and if so why?

like image 434
Peter Avatar asked Jan 18 '23 08:01

Peter


2 Answers

To answer your actual question as to whether using TagLibs to expose the JavaScript functionality is an advantage, my answer would be generally no. But you're likely to get just as many people disagree with me as those that would agree. Especially folks that have spent time creating these TagLibs.

I just find it much easier to deal with the JavaScript directly than to go through a taglib. The only exceptions I might consider are the grails given remote taglibs but I still don't use them, personally.

like image 140
Gregg Avatar answered Jan 20 '23 22:01

Gregg


Personally, I prefer to use the JavaScript taglibs over plain JavaScript. For example, if you want to create a link that submits an AJAX request and updates a DIV with the response I find it easier to write

<g:remoteLink action="show" id="1" update="myDiv" 
        onLoading="showSpinner();">Click Me</g:remoteLink>

than the corresponding JavaScript.

If you have the JQuery plugin installed and decide you want to replace JQuery with Prototype (for example), the tags above should continue to work once you've replaced the JQuery plugin with the Prototype plugin. This would not be possible if you just copied the .js files into web-app/js (instead of using the plugins).

Ultimately, if you use the JS plugins, you application "knows" which JS libraries are using. Other plugins (e.g. resources) can then use this information to your advantage.

like image 20
Dónal Avatar answered Jan 20 '23 21:01

Dónal