aspose file tools*
The moose likes JSP and the fly likes jstl problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl problem" Watch "jstl problem" New topic
Author

jstl problem

Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
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
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Try this


[ January 24, 2006: Message edited by: Adeel Ansari ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
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"><cut 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

Joined: Jul 24, 2003
Posts: 260
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 15, 2004
Posts: 2874
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl problem