aspose file tools*
The moose likes JSP and the fly likes Bean's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Bean Watch "Bean New topic
Author

Bean's "if" inconsistencies.

Charessa Reilly
Ranch Hand

Joined: May 26, 2011
Posts: 39
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
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

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

Joined: May 26, 2011
Posts: 39
Sigh. I have so much to learn.

Thank you very much, that did it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Charessa Reilly wrote:Sigh. I have so much to learn.


That one was a gotcha for almost all new Java programmers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean's "if" inconsistencies.