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.

22 comments:

  1. 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

    ReplyDelete
  2. 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. www.menstopspot.com | www.pureitfresh.com | www.warmmensfashion.com | www.urbanplussizeclothing.org | www.burgundybodycondress.com

    ReplyDelete

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

    ReplyDelete

  4. 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.

    ReplyDelete

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

    ReplyDelete

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

    ReplyDelete
  7. Good post thanks for share information. utsa blackboard

    ReplyDelete
  8. 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

    ReplyDelete
  9. 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 Jennycasino.com frequently updates the casino bonus page. Therefore, I can select any online casino bonus from one page of the site https://jennycasino.com/casino-bonuses/ , and also, all gamblers can carefully study the descriptions of each bonus presented.

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

    ReplyDelete
  11. j1j95f6z62 v9k13r0t97 j4k27v5z25 n9e67z6y49 o5b68r5h63 b8m01f2c20

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

    ReplyDelete
  13. Bring balance to your soul and boldness to your look with Apna Showroom’s divine 7-in-1 combo. Featuring a sacred Brass Gangajal Kalash, Feng Shui tortoise, energizing crystal, powerful Shaligram Shivling, Rudraksha mala, floral Five Rose Pin, and statement fishnet stockings,Apna Showroom Baby's Cotton Panties/Bloomers/Underwear 12 Pieces (3-4 Years)
    Apna Showroom Baby Girl's and Baby Boy's Panty Combo (Multicolour, 9-12 Months) -12 Piece Designer and Attractive
    Baby Panties 0-3 Months Newborn for Boys Girls Combo Pack Set or Bloomers or Underwear with desent Look Designer - Fancy - Attractive 12 Piece | Apna_Showroom
    Apna Showroom Baby Girl's and Baby Boy's Cotton Panties Fancy and Designer (Multicolour, 3-6 Months) -12 Piece
    Apna Showroom Baby Skirt Frock Dress for 6-12 Months - 1 Year Dress skirts frock girls Black
    it’s a fusion of pooja and personality. Ideal for spiritual women who want to align their energy and embrace their edge. Transform your aura and altar—order now and feel the sacred shift.

    ReplyDelete
  14. The Nano Gps Chip Market is gaining traction as demand surges for compact, low-power location tracking solutions in wearable devices, pet tracking systems, asset monitoring, and consumer electronics. These tiny chips offer high precision and integration flexibility, making them ideal for space-constrained applications. The advent of IoT and growing interest in real-time tracking for personal safety and logistics are key drivers of market growth. Manufacturers are focusing on improving signal sensitivity, energy efficiency, and multi-constellation support to enhance performance in various environments, from urban areas to remote locations.

    ReplyDelete