• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing values  RSS feed

 
sue gari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to compare something like the following <c:if test="${id.employmentID }><%= Integer.parseInt(anchorValue) %>"> or <c:if test="${id.customerID }>${anchorValue} %>">. Basically employmentID and anchorValue are both strings. I am checking if customerID is greater than anchorValue but the following code above does not seem to work. I would appreciate if someone can suggest an alternative. Thanks.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't mix JSTL and EL with scriptlets.

What is anchorValue? If it's a scripting variable, change it to a scoped variable and be sure to remove all scriptlets from the page. Use JSTL and EL only!

If it's a scoped variable aleady, it's easy:

If you want to compare them numerically, make sure that they are numeric values before they get to the JSP page.

The rule of thumb to remember is to make things as easy as possible for the JSP. Perform any data manipulation in the controller so that the JSP is brain-dead simple.
 
sue gari
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for thread hijack, I might as well ask
is it always better to use tags instead of scriptlets?
Or do you use scriptlets only when you have no choice but to?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets should never be used. Ever. There are modern mechanisms to do whatever needs to be done on a JSP. And if it's a lot of work to do so, then it's a good clue that what you are trying to do isn't something that belongs in s JSP in the first place.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what is the point of having scriptlets there then?
Seems a waste to me...although I'll hate to use them because they're hard to read!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets are an artifact of the past from JSP 1 days before the JSTL and EL. They are the equivalent of stone knives and bearskins from the Stone Age.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh right, I see lol
I am still getting used to it...but I have to say it is hard learning
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!