> Which is StringUtils.trim. Already there.
> Like Dave, I'm not sure I can see converting "" to null as a highly
common
> thing to do. In fact, I'd expect people to want the reverse more often
> [which I suspect Dave might like}, convert any null passed in into "".

>Leonardo, what's the use case for StringUtils.trimNull( str)?
>I, like Hen and Dave, have difficulties seeing one that occurs often
for >most people, 
>which would motivate inclusion.

A use case could be in a web application. When I get data through an
HTML form, sometimes I'd like to treat whitespaces as null values
(meaning that the user didn't provide any information). In this case,
*null* is a special value, not a nuisance. 

A QBE (Query By Example) could get a JavaBean with some fields filled
with data, and some nulls. The data fields are included in the query,
while the null ones aren't. 

You would say, what if the whitespace *is* the special value? Well, I
would like to change the web interface later and provide checkboxes in
the form. The checked properties are taken into account, even if they
have whitespace. However, we wouldn't  need to change the business logic
of the QBE, because it always had nulls as "no values". Even more, the
program is more robust, because if by accident one of the request
parameters didn't show up (giving a null value), the business logic is
ready for that. If we have to check for empty strings, on the other
hand, a null value could get us a NullPointerException.

That's just an example. There could be several other examples where NULL
is important, and it would be useful to turn empty strings into nulls. 
That's why I think the method would be useful.

Leonardo 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to