my dog learned polymorphism*
The moose likes Struts and the fly likes check for a space with the form bean validate method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "check for a space with the form bean validate method" Watch "check for a space with the form bean validate method" New topic
Author

check for a space with the form bean validate method

jakes vandenberg
Greenhorn

Joined: Nov 05, 2004
Posts: 14
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

Joined: Nov 05, 2004
Posts: 14
does anybody have any idea??
PLEASE HELP!!!
jakes vandenberg
Greenhorn

Joined: Nov 05, 2004
Posts: 14
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

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: check for a space with the form bean validate method
 
Similar Threads
form bean and validation.
form validate()
strut validation frame work issue
Validation
Validation