Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic