Saturday, January 28, 2012

Struts 2 - Dynamic Map Key

To get a value from a map that is in our action class declared as:
    private HashMap<String, String> Values;
with a getter decalred as:
    public String getValue(String key) {
        return Values.get(key);
with a key declared as:
    private String keyName;

In the JSP, call the getter like this:
    <s:property value="%{getValue(keyName)}"/>

No comments:

Post a Comment

Thank you for commenting!