I would like to display HashMap keys and its associated value in the JSF UI.
How can I achieve this? How can I iterate over a HashMap in JSF page using some iterator component like <h:datatable>?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Only
<c:forEach>supportsMap. Each iteration gives aMap.Entryinstance back (like as in a normal Javaforloop).The
<h:dataTable>(and<ui:repeat>) only supportsList(JSF 2.2 will come withCollectionsupport). You could copy all keys in a separateListand then iterate over it instead and then use the iterated key to get the associated value using[]in EL.Noted should be that a
HashMapis by nature unordered. If you would like to maintain insertion order, like as withList, rather useLinkedHashMapinstead.