• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jstl problem

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..
I have a one class which is returning me a location number in jsp file like this ,here currentLocno is declared as a int type.
& one map contains location ids as key of type String against the objects of the Location class .

hashMap is like

{1600=com.track.model.Location@1af8502,
2203=com.track.model.Location@455aa8,
5305=com.track.model.Location@143073a,
5101=com.track.model.Location@18facfb,
3112=com.track.model.Location@1a59490}

now in my jsp file if I hard code the location-code like locHash["1600"].locName then I am able to get the location no.
and if I do like then it does't print anything
so I just want to know how to convert
${jsheet.currentLocno} (primitive type) to Object type (String)
using Expression language so that I can get the location no.

thanks
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this


[ January 24, 2006: Message edited by: Adeel Ansari ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That won't work -- you cannot call a general method in the EL.

Besides, no conversion to String is necessary at all. If you are getting no output, it's because your reference isn't correct, not because any conversion needs to be done.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the hashMap has keys of type String.
${jsheet.currentLocno} in EL would evaluate as an Integer.

Using an integer to look up on the map obviously won't find the key
new Integer(1600).equals("1600") will always be false.

So either
- change the keys of the map so that they are Integer instead of String.
- get EL to convert ${jsheet.currentLocno} to type String, which you can then use to look up the appropriate map value.

This would do it:
<c:set var="mapKey"><c:out value="${jsheet.currentLocno}"/></c:set>
${locHash[mapKey].locName}

alternatively as you seem to have a JSP2.0 container, use an EL function. fn:trim should do the job (hack hack)
${locHash[fn:trim(jsheet.currentLocno)].locName}

Good luck,
evnafets
[ January 24, 2006: Message edited by: Stefan Evans ]
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..Stefan
thanks for it
I have tried this and it is working


but I Stefan I didn't change my keys to Integer its working fine with the String also.
and Adil thanks for reply but Bear told we can't call a gernal method in EL like

thats true...

thanks for all of you for supporting me...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Our pleasure. One thing to try and keep in mind is to try and keep the data structures that you send to the page as EL-friendly as you can. That way, you keep complexity and weirdness off the pages.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
That won't work -- you cannot call a general method in the EL.



Thanks Bear. I didn't know that. Actually never tried it myself, nor read this anywhere. May be because I usually practice best practices. Anyways, thanks once again.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
One thing to try and keep in mind is to try and keep the data structures that you send to the page as EL-friendly as you can. That way, you keep complexity and weirdness off the pages.



Cent percent agreement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic