Forums Register Login

Get value from HashMap attribute

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2723 times.
Similar Threads
Cade's BDM and Model
Problem populating a newly created HashMap in a Struts2 Action
How to use s:set in Struts 2
Attribute Problem
Acessing value of attribute
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:47:39.