Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string to Integer comparison in jstl

 
Rick Prows
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems like a dumb question to me - but I can't figure out what I am doing incorrectly.

In my jsp page i am trying to do the following:


financialInstitutionNumber is an Integer and in this example is an 11
securityBean.divisionNumber is a String and in this case is 011 (fixed 3 characters in length)

It is not getting inside this If statement. Is there a way I can cast the String to an Integer in this code?

Not sure why I am drawing a blank - but I couldn't find anything online that shows it.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all else fails, convert the Integer into String.

Add a getAxxxx method in finInst class which returns the 0-left-padded-String-version of that Integer; and thereby use "finInst.axxxx ==" in jstl.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the data so dirty to begin with? Clean it up before sending it along to the JSP. The JSP is no place to be performing gyrations on data that's not in a good format for consumption.

P.S. If I recall coercion rules correctly, the values are being coerced to strings, so "11" != "011".
 
Rick Prows
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are coming from different sources. The security bean is a corporate bean and division number is stored as a character.

the rest of the code is at the application layer and the division number is an integer in that application.

i have a solution, definately not the best solution, but it does seem to work. I'm sure there is probably an instance where it might show when it shouldn't, but the solution I used is:

fn:contains(securityBean.divisionNumber,finInst.financialInstitutionNumber)

where as it checks to see if the interger value is contained in the String value.
Not the best solution, because division 11 would work in 011, 511, 611, and 110.

still looking for a better long-term approach though
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can't "fix" the data in the page controller, at minimum I'd write an EL function that converted "011" to 11 for comparison. I would not consider your current comprise an acceptable solution.
 
Rick Prows
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok - I went with Jesus recommendation. I put a getter in my base action that converted my securityBean string to an Integer and then I referenced that in my jsp.

Thanks all for your time and recommendations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic