I had several domain classes with long text content that I wanted to display just a summary of on the screen, especially in lists columns, etc.. I first added a getIntro(int numChars) method on domain classes with long strings, and used them when appropriate.
But I soon realised that I violated the DRY principle (Dont Repeat Yourself) with getInto() methods all over the place. I could have put the method in a base class but my text properties did not have the same name in all domain classes, so that was complicated.
I think I found a much better solution. I removed all those methods and added a getIntro(int) method to String and GString in BootStrap.groovy.
A collection of articles and resources of interest to the modern software developer
Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do.
-- Steve Jobs
Friday, October 14, 2011
Grails - Add method on String to truncate long texts nicely | technipelago
Add method on String to truncate long texts nicely
Labels:
Formatting,
Grails
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment