• Post Reply Bookmark Topic Watch Topic
  • New Topic

boolean code question  RSS feed

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't figure out why this isn't working:
all foo_ values are null, usefooUnique is ""
I would have thought the last test would have caught that but it falls thru

thanks
Max

if ((this.foo_1==null)
&& (this.foo_2==null)
&& (this.foo_3==null)
&& (this.foo_4==null)
&& (this.foo_5==null)
&& (this.foo_6==null)
&& (this.foo_7==null)
&& (this.foo_8==null)
&& (this.foo_9==null)
&& (this.foo_10==null)
&& (this.foo_11==null)
&& (this.foo_12==null)
&& (this.foo_13==null)
&& (this.usefooUnique.equals("00") || this.usefooUnique.equals(""))) {
errors.add("fooRequired", new ActionError("error.foo.required"));
}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you provide a little more of your code, and also what you mean by "falls through"?

Also it looks like you could save yourself a lot of code by making foo an array of booleans.
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keith -
Not much more code to provide, sorry. This is a Struts form class which I am trying to fix.

The form class is testing for 13 initial values, all which are null.
The last test --

&& (this.useFooUnique.equals("00") || this.useFooUnique.equals("")))

--

is supposed to catch useFooUnique if it's "00" OR "" ... in this case it's "" and the 'if' statement doesn't return true ... which I would have htought it would have done...

I agree with the array of booleans and will refactor when I get that far.

thanks
Max
[ December 08, 2006: Message edited by: Max Tomlinson ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it's "" and not null?
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Are you sure it's "" and not null?
And not " " and not " "?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Are you sure it's "" and not null?


this.usefooUnique.equals would throw a NPE is it was, wouldn't it ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:

this.usefooUnique.equals would throw a NPE is it was, wouldn't it ?




We need a better "Doh!" icon than that; it doesn't convey exactly the right sentiment, but you know what I mean. Thanks.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have a feeling that would get massively overused if added to our palette of smilies.
 
vijaya bharath
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

foo_values are objects or variables?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!