• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean's "if" inconsistencies.

 
Charessa Reilly
Ranch Hand
Posts: 39
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yay! Another post from me!

I've got an if statement in a bean that seems to be processing fine when I create a test java class, but doesn't work fine when the bean is invoked by a jsp.

My code, let me shows you it:

First, the test class:


a snippit from the IrCollection class it calls:



There's more code in another method that calls this particular method using:

But the problem is that if (datum=="none") portion in the second code sample. Given that line 10 of the first class sets the member variable sort to "none", that processSort() method should set the member variable fullSort to " ORDER BY lastUpdated DESC"

And if I use the class in the first sample, it does that.

HOWEVER

I have this custom tag:


Which the .jsp file invokes with this:


In other words, the exact same data is fed to the IrCollection bean. so I should get the same data, right?

Except I get this:
WHERE cotr = 'none' ORDER BY non DESC


so when Java calls it, it thinks "none" == "none"
but when jsp calls it, it thinks "none" != "none"
 
Paul Clapham
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the == operator to compare the contents of two strings in Java. That line of code should read


(However the == operator DOES compare the contents of strings in the JSP's expression language.)
 
Charessa Reilly
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh. I have so much to learn.

Thank you very much, that did it.
 
Paul Clapham
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charessa Reilly wrote:Sigh. I have so much to learn.


That one was a gotcha for almost all new Java programmers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic