• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get value from HashMap attribute

 
matej spac
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!