Pages

Thursday, July 26, 2012

Accessing and Iterating HashMap Values

This post covers how to access value for a particular key in HashMap  and iterate over the HashMap.


First we will cover access value for a particular Key in HashMap : -

1. Create a HashMap in bean. Say we have changeMap in testMapBean.
2.  To Access value for key 'abc', use following expression #{pageFlowScope.testMapBean.changeMap.abc}

Simple !

Iterate Over values of HashMap : -

1. Create a HashMap in bean.
2. Create a method returning entrySet array for HashMap.
3. Bind iterator to entrySet returned and access each value using expression : #{row.value}

Sample application can be downloaded here ( HashMapAccessApp ).