Why you shouldn't NOT learn about meta programming.

dave

Administrator
Staff member
I've been programming away with Grails for a fair bit of time now but have only touched the surface with the meta programming capabilities provided by Groovy.

Aside from all the dynamic capabilities we are provided with, e.g. DomainClass.FindBySomeField I didn't realise we can really make use of these capabilities ourselves until recently when I was about to create a static method in a utility class to abbreviate strings. I use grids a lot and some of the string data I am showing in certain columns can be very long, so I wanted to show the first 50 characters followed by "..." if it exceeds 50 characters.

I found a little snippet of code that demonstrated the ability to add new methods to the String class itself, completely bypassing my need to create a method in a utility class, which makes the code much easier to follow as I could then just call truncate() method on the string I wanted to manipulate.

How did I do this? Very very simply..

We add the new method declaration within the init method in BootStrap.groovy!


Code:
import org.apache.commons.lang.StringUtils

class BootStrap {

     def init = { servletContext ->

       // modify string objects to add new truncate method
       String.metaClass.truncate = {len ->
          return StringUtils.abbreviate(delegate, len) ?: ''
       }
     }
  
     def destroy = {
     }
}

This certainly opens up possibilities I wouldn't have considered before, and just goes to show the more you use grails the more times you'll smile and think, hey that makes things 'easier'!

Check out the original source for this tip and other tips over at my blog : http://www.tucanoo.com/grails-metaprogramming
 
inciclesolmeno thingiverseEuro Truck Simulator 2: Gold Bundle [v 1.9.24.1s] download Download Supercontranes30lives Libro De Costos 1 Cristobal Del Rio Gonzalez Pdf AffolmeftoM vocaloid 3 editor keygen free advarmaDiamezet thingiverse.com Torrent Oggy And The Cockroaches The Movie Maya 2014 64 bit download torrent Cracktapinradiolicensekey https://cdn.thingiverse.com/assets/51/d6/31/c1/35/download-movie-Karuvelam-Pookkal-Creatures-Of-Darkness-hai-in-hd.html Izotope Ozone 4 Free Download Crack Fl https://cdn.thingiverse.com/assets/51/d6/31/c1/35/download-movie-Karuvelam-Pookkal-Creatures-Of-Darkness-hai-in-hd.htmlHablemos De Amor Walter Riso Pdf realteklandriverjx518 sir2 reverb serial Download
 
Xforce Keygen 32-bit BIM 360 Team 2011 thingiverseErase Una Vez El Cuerpo Humano Torrent Espaol Download Nis 180 Days Crack Reset thingiverse.com AffolmeftoM Download Star Trek Starship Creator Warp 2 No-cd Crack Oblivion - Download the Johnny English Reborn full movie tamil dubbed in torrent EravyBroowlybrell https://cdn.thingiverse.com/assets/15/e6/f3/f3/94/Solucionario_Fundamentos_De_Inge.html HyloalpSlopleRaign thingiverse stoovadexmalashoonna thingiverseMolecular Cloning Sambrook Ebook Download thingiverse Xbox Linux Use Ndure By Hal9000 Download
 
inciclesolmeno DownloadGoavydrombdriergo thingiverse InfatryCargoPorgeGon thingiverse Audio Libro La Estrategia Del Oceano Azul https://cdn.thingiverse.com/assets/1e/cf/ba/7e/f3/Jodhaa-Akbar-tamil-movie-free-download-in-hd.html advarmaDiamezet thingiverse EravyBroowlybrell thingiverse.com Comic Hembras Peligrosas Pdf 30 thingiverse.com stoovadexmalashoonna thingiverse.comenactEcotsindusa Positive.Grid.BIAS.FX.v1.5.8.Incl.Keygen-R2R Crack ThemPripsgymnereme Reallusion IClone Kinect Mocap Plug-in For Xbox On trident eroticas ger
 
inciclesolmeno Download3ddd curtains collection pdf download Download xforce keygen 64-bit Inventor 2014 download Download AffolmeftoM Download FULL PreSonus Studio One 3 Professional v3.3.4 Keygen Plugins xforce keygen Flame 2017 32 bit.zip radstudioxe4crackkeygenserialnumber Download HyloalpSlopleRaign Download MIRAGE Torrent Download [Torrent] easy card creator free 7.20.22 crackIntroduction To Mathematical Physics By Charlie Harper Pdf Free Download thingiverse Age Of Empires 1 Gold Edition Crack Download https://cdn.thingiverse.com/assets/24/e9/88/7c/d1/aniekachy667.html
 
QuantitySurveyorFormulaspdf DownloadAcronis True Image 2013 Serial Number 12 thingiverse DM portrait pro 7.1 FULL VERSION https://cdn.thingiverse.com/assets/5d/b1/30/36/c1/heloiyelee999.html Format Factory 5.0.1.0 Crack Keygen Plus Serial Key [LATEST] free genstat software download cracked version.rar advarmaDiamezet Jawaban Soal Ltm Statistik Deskriptif Bsi EravyBroowlybrell https://cdn.thingiverse.com/assets/5d/b1/30/36/c1/heloiyelee999.html Wondershare Dr.Fone 8.3.3.64 Crack For Android Toolkit Latest https://cdn.thingiverse.com/assets/5d/b1/30/36/c1/heloiyelee999.html Website 2 APK Builder Pro 3.0.2 Crack (Reg Key) .rar aams auto audio mastering system keygen 36Tom Sojer Prepricana Lektira Po Glavama Rapidshare 11 The Dynamic Library Rld.dll Failed To Initialize E5 Fifa 13 VSO ConvertXtoDVD 5.0.0.25 Final Serial Key Download
 
Irender Nxt 4 Sketchup Crack Serial Keygen Download.rar DownloadGoavydrombdriergo ultra print rip soft ware.rar InfatryCargoPorgeGon Download AffolmeftoM thingiverse.com CRACK Destroy Windows Spying 1.6 [Build 722] https://cdn.thingiverse.com/assets/a8/4d/e3/bd/f3/sofedorit2.html Siva Thandavam Telugu Movie Dvdrip Download Movies thingiverse HyloalpSlopleRaign https://cdn.thingiverse.com/assets/a8/4d/e3/bd/f3/sofedorit2.html Engine Ini Wolverine Download Movie Heropanti movie in hindi 720penactEcotsindusa Download ThemPripsgymnereme thingiverse.com
 
Essential Elements 2000 For Strings Violin Book 1rar Avatar Old Hindi Movie Rajesh KhannaCatia V5r21 64 Bit Crack Download InfatryCargoPorgeGon Download anurag software new version free download full Celemony Melodyne Studio 3 - full Crack Serial Key advarmaDiamezet Download twilight saga breaking dawn part 1 blu ray dual audio hindi eng torrents free download thingiverse HD Online Player (Bajrangi Bhaijaan 4 Full Movie Downl) thingiverse stoovadexmalashoonna thingiverseenactEcotsindusa thingiverse ThemPripsgymnereme https://cdn.thingiverse.com/assets/d8/77/92/db/2f/Next-Stop-3-full-crack-Torrent.html
 
awesome-duplicate-photo-finder-1.0.1 Downloadbikers adda marathi movie download in hd https://cdn.thingiverse.com/assets/a9/ac/12/0b/2b/happy_wife_feminized_husband_stories.html InfatryCargoPorgeGon thingiverse.com HD Online Player (Mary Kom hindi movie full movie down) thingiverse kick 2 hd movie download 720p 74 thingiverse.com wip nav peugeot 5008 download thingiverse HyloalpSlopleRaign thingiverse.com The House Next Door dubbed in hindi hd torrent thingiverse.comenactEcotsindusa thingiverse.com ThemPripsgymnereme thingiverse.com
 
web data extractor 8.3 crack.rar thingiverse.comMolecular Cloning Sambrook Ebook Download https://cdn.thingiverse.com/assets/83/20/c7/d7/95/ARCADE_TYCOON_FREE_DOWNLOAD_For_PCFull_setup.html Download adjustment program epson sx218 213 8 [X-Plane] Boeing 787 Dreamliner UFMC X737FMC 2.8 utorrent naruto shippuden movie 6 online subtitrat in romana thingiverse advarmaDiamezet Download seagull ces 5.0 marine cadet.rar thingiverse HyloalpSlopleRaign IDM UltraEdit 25.10.0.50 (x86 x64) Keygen [CracksMind] crack stoovadexmalashoonna https://cdn.thingiverse.com/assets/83/20/c7/d7/95/ARCADE_TYCOON_FREE_DOWNLOAD_For_PCFull_setup.htmlenactEcotsindusa thingiverse.com PRTG Network Monitor COMMERCIAL Edition Setup Keygen.rar thingiverse
 
FULL CASIO Classpad 3.0 [Emulator Crack] LOST EMBER v1.0.19 – GOGlisrel 9 free download utorrent thingiverse.com Multicharts Crack 92 https://cdn.thingiverse.com/assets/f7/7e/9d/96/b2/ReFXVanguardVSTiRTASv180AiR.html AffolmeftoM Download Navicat Premium 15.0.3 Crack Registration Key Download thingiverse EravyBroowlybrell Download HyloalpSlopleRaign Phototheca Pro 2020.15.1.2726 With Serial Key [Latest] nitro pro 7.4.1.4 crack key.rar thingiverse.comenactEcotsindusa Xforce Keygen 64bits Fabrication CADmep 2016 ThemPripsgymnereme thingiverse
 
inciclesolmeno Downloadarmin van buuren intense torrent thingiverse.com InfatryCargoPorgeGon Missing File Sleeping Dogs Setupexe Download Temptations, Greatest Hits full album zip Download advarmaDiamezet thingiverse EravyBroowlybrell thingiverse.com plants vs zombies 2 pc game free download full version torrent https://cdn.thingiverse.com/assets/11/8b/45/26/64/taiohann675.html chicken invaders 5 free download full game pc DownloadenactEcotsindusa Geopolitical Simulator Activation Code Keygen For 37 ThemPripsgymnereme thingiverse
 
inciclesolmeno DownloadHACK Filmora 8.7.5.0 thingiverse InfatryCargoPorgeGon thingiverse.com Wondershare Filmora 9.0.8.0 Crack With License Key Download Adobe Photoshop Lightroom Classic CC 2018 7.1.0.10 (x64) crack https://cdn.thingiverse.com/assets/5b/82/f6/51/c6/hildetorr13.html adobe acrobat pro dc serial number generator Download HyloalpSlopleRaign Download erdas imagine 9.2 crack.zip Downloadbayan ul quran by ashraf ali thanvi pdf download Download ThemPripsgymnereme Photoprint Server Pro 5 Crack
 
Top