• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Common Bean Utils

 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,
I am building web application using Struts.
I want to copy the value of a form into a value object using Bean Utils.
Does BeanUtils.copyProperties method include trimming process for every value of the form?
Or do I have to do trimming process manually before I use BeanUtils.copyProperties method?

thanks
daniel
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you must create trim() process before call PropertyUtils.copyProperties(). because this method not have trim() process.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you could trim() in your value object setter method.
eg.

public void setName(String name) {
this.name = ((name == null) ? null : name.trim());
}

do this for all your String attribute
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use StringUtils.trim() to reduce your code lines.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Siripa Siangklom:
you can use StringUtils.trim() to reduce your code lines.



yep, its good point.


StringUtils.trim( ) delegates to the trim( ) function on String and gracefully handles null. When you pass a null to StringUtils.trim( ), it returns a null.




And you can use trimming to NULL of StringUtils ::

Example



 
reply
    Bookmark Topic Watch Topic
  • New Topic