Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check for a space with the form bean validate method

 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my scenario:
I have an input box on my form. If I highlight text and press space to clear it, the form still contains a space, but no text.
In my form bean I have a validate method and was wondering how I can check for this space.
I tried the following without success:

if (Code2 == "") {

if (Code2 == "\u0020") {

if (Code2 == " ") {

Thanks
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does anybody have any idea??
PLEASE HELP!!!
 
jakes vandenberg
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
peeps,
Nevermind, I figured it out. I just had to think about it a little bit and go back to "RTFM"!!

Since it is a String, use String.equals(" ").
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be more efficient to trim it and compare it to empty string so that you can handle a string with multiple spaces.

Code2.trim().equals("");

OR you could set up a filter to automatically trim all incoming request parameters. That would make such validation unnecessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic