Fork me on GitHub

21 May 2011

Resources plugin and modular web components for Grails apps

I recently gave a talk on ‘Building progressive UIs with Grails’ at gr8conf in Copenhagen and was really pleased with the feedback & comments I received afterwards. There was a question asked at the end that I felt in retrospect I could have answered better, though. I had mentioned that the Grails AJAX tags were something that should be avoided as they write script blocks directly into the page and event handlers directly onto HTML elements. I was pitching an approach based on a clean separation of clean semantic markup and script enhancements and inline script violates that separation.

I was asked if there might be any kind of tags that could be developed that provided a more appropriate replacement and answered that since modern JavaScript frameworks such as jQuery make decorating elements with AJAX functionality so easy that I didn’t think there was much point.

I wouldn’t want anyone to understand me to mean that creating taglibs and GSP templates for modular components of your pages is a bad thing. I’d just advocate keeping the script out of them. Custom tags that write out markup or delegate to templates can be really useful for building complex reusable modules. Pairing those with external JavaScript files that enhance the generated markup would be very effective.

If you’re using the resources plugin (and really… you should be) then there’s a really neat way to tie the taglib or template to the JavaScript file as well. I did briefly mention this in my talk but it’s worth expanding on here as it’s a technique with a lot of potential.

The resources plugin’s r:use tag doesn’t write out anything directly to the page but rather adds a resource module to a list that will get written out at the appropriate place in the page when the r:layoutResources tag is used. This means modular components throughout the page can declare a dependency on JavaScript and CSS resources by simply calling r:use. In a complex app this can be a real boon as it might not be obvious from the top level GSP exactly which modules are going to get rendered. Also if a module is later added to or removed from a page you don’t need to worry about fiddling around with resource declarations in the top level GSP. Taglibs or templates become real drop in components whilst maintaining a nice clean separation of markup and script. Even better, if you use the same resource dependency multiple times the plugin ensures the resources are actually only linked once.

Since r:layoutResources is typically used in a SiteMesh layout the resources your module depends on can even be ones that need to appear in the head of the document. The SiteMesh is rendered after the GSP it decorates so any r:use calls will already have been made.


Unknown said...

You blog post is just entirely quality and useful, many new facts and information which I have not heard about before.
essay writing service reviews

Unknown said...

Can I simply say what a comfort to discover someone who actually understands what they're discussing on the web. You certainly realize how to bring an issue to light and make it important. More and more people need to check this out and understand this side of your story. It's surprising you aren't more popular given that you surely have the gift. | | | |

我愛你 said...

What you do is beautiful and very sexy. Please take care and do not shorten what you do
العاب سباق 2018
العاب طبخ
العاب تلبيس

nandhu said...

zapya for windows
zapya pc
zapya apk download
zapya free download
In the end, one friend sends around two snapshots and everyone else forgets about it.

Akira said...

Eng vs SA World Cup 2019
Wi Vs Pak wolrd Cup 2019
When Is fathers day 2019
Happy 4th Of July Images

شركة رواد الحرمين said...

شركه تنظيف منازل بالدمام
أيضاً تسبب في سقوط الطلاء وظهور التشققات، ولكن من الآن لا داعي

Tech Solitic said...

TechSolitic Windows 7 issues.

akshayavengala said...

mobdro apk
mobdro app
mobdro download
mobdro for android
It is also among the best live streaming apps.

homa hakeem said...

شركة عزل اسطح بجازان
شركة مكافحة حشرات بجازان
شركة نقل اثاث بجازان
شركة كشف تسريات المياه بنجران
شركة تنظيف بخميس مشيط
شركة تنظيف منازل بخميس مشيط
شركة تنظيف خزانات بخميس مشيط
شركة كشف تسربات المياه بخميس مشيط
شركة مكافحة حشرات بخميس مشيط
شركة رش مبيدات بخميس مشيط

sandeepaleti36 said...

snapchat on dark themeThank for sharing this awesome post love to read this.

aditya said...

Good post thanks for share information. utsa blackboard

المتوكل على الله said...

شركة تعقيم بالرياض
شركة جلى بلاط بالرياض
شركة تنظيف خزانات بالرياض
شركة تنظيف فلل بالرياض
شركة تنظيف ارضيات بالرياض
شركة تنظيف مسابح بالرياض

James David said...

Nice post, it is useful for me. It is very informative. Such a great post as you share it. by logo for embroidery online in usa said...

Thank you very much for the post, he raised a very interesting topic. Any online casino player wants to be given bonuses. No deposit bonuses for registration before the game and others for a deposit. And naturally I also really want to get them. In general, I am very pleased that frequently updates the casino bonus page. Therefore, I can select any online casino bonus from one page of the site , and also, all gamblers can carefully study the descriptions of each bonus presented.


I do appreciate for sharing of informative articles for Ad-Hockery. Thank you so far sincerely cheap digitizing :)

logger said...

pirate embroidery design
pooh and eeyore embroidery design
rabbit embroidery design
ring embroidery design
scorpion embroidery design
shego kim possible embroidery designs

shenes said...

this contenttry this website More about the authorwhy not try these out find more infobest site

Unknown said...

j1j95f6z62 v9k13r0t97 j4k27v5z25 n9e67z6y49 o5b68r5h63 b8m01f2c20

Hart Williams said...

Definitely! With Embroidery Pattern Digitization, think of it like UI development in Grails. Using modular components makes our embroidery designs both intricate and organized.