• 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

Get value from HashMap attribute

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I can´t get value from attribute object of type LinkedHashMap.

I have got this 2 attributes:
1. LinkedHashMap<Integer, String> object saved under name "manufacturers"
2. JavaBean object saved under name "product" with some properties

I try following in my JSP:



But I want to get values from LinkedHashMap based on ${product.manufacturer} value as a key. When I try to do it with:

it is not working, nothing is returned.
Separately both attributes is returned (with all kind of syntax above), but when I combine them, something goes wrong.

What am I doing wrong?
 
matej spac
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually even ${applicationScope.manufacturers[1]} did not work.
So I change map from LinkedHashMap<Integer, String> to type LinkedHashMap<Long, String>.
Now at least ${applicationScope.manufacturers[1]} works and return "Value1" as expected.

But ${applicationScope.manufacturers[product.manufacturer]} still not working
 
matej spac
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nice talk

I found problem:

${applicationScope.manufacturers} refers to LinkedHashMap<Long, String>
${product.manufacturer} refers to variable of type int

So ${applicationScope.manufacturers[product.manufacturer]} returns nothing.

I change type of variable ${product.manufacturer} from int to Long and now it is working
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic