Dinamically trim all object\'s string properties


/ Published in: Groovy
Save to your folder(s)

I used this because I had a legacy db table that all fields are char. the right spaces were a pita. The rightTrim function can be viewed in my profile


Copy this code and paste it in your HTML
  1. static void trimObjectProperties(GroovyObject o,String wichSide)
  2. {
  3. o.getProperties().each{
  4.  
  5. if(wichSide.equals(RIGHT)) //you can add more trim types
  6. {
  7. if(it.value)
  8. if(it.value.class.equals(String.class))
  9. {
  10. o.setProperty(it.getKey(), rightTrim(it.value)) //call the trim method
  11. }
  12. }
  13. }
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.