Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Casting String to int In EL  RSS feed

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bean of 2 properties, say bean.noOfPages & bean.pageNo. Both are of String type, and I want to compare the 2 by EL:

<c:if test="${bean.noOfPages lt bean.pageNo}" >
..

However, when bean.noOfpages="20" and bean.pageNO="101" the expression is false because I am comparing 2 Strings. Is it possible to force an integer comparison?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point of JSP 2.0, the JSTL and the EL is to keep JSP pages simpler. When designing web apps, pages should no longer contort themselves to swallow whatever is being passed to them. Rather, the Java components should cater to the needs of the page -- not the other way around.

So the correct approach would be to recognize that it's the bean that's broken, not the page.

If the page needs ints, that's what the bean should make available.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!