IntelliJ Java IDE
The moose likes Other Open Source Projects and the fly likes Common Bean Utils Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply Bookmark "Common Bean Utils" Watch "Common Bean Utils" New topic
Author

Common Bean Utils

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
you must create trim() process before call PropertyUtils.copyProperties(). because this method not have trim() process.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Paul Strachan
Greenhorn

Joined: Oct 24, 2004
Posts: 10
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
Siripa Siangklom
Ranch Hand

Joined: Jan 26, 2004
Posts: 79
you can use StringUtils.trim() to reduce your code lines.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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



 
IntelliJ Java IDE
 
subject: Common Bean Utils
 
Threads others viewed
how to populate values in jsp page
Html Select - to make an option selected
what do I need to do to use BeanUtils.copyProperties?
Basic Struts Forms question
Build Error - beanutils
IntelliJ Java IDE