tags:

views:

370

answers:

1

Hi,

when my Map contains key with dot in their name I cannot access the corresponding value directly with the usual code:

${recordForm.map['records.key']}

Is there a way to escape the dot? Or do I have to resort to loop through all values and check against the key? (I know the iteration works).

Thanks!

A: 

It should work. Your problem lies somewhere else. Either you aren't running the code you think you are, or you changed the original code "too much" for posting this question and it became correct by coincidence.

[Edit] As an anwer on your comment here below: it certainly works. I even created a quick-n-dirty SSCCE for you (quick-n-dirty as in: using scriptlets while you shouldn't be doing this in real -java code belongs in a java class):

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>

<%
    // NOTE: this code belongs (in)directly in a Servlet class.
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("foo.bar", "fubar");
    map.put("beh.moo", 1234567);
    request.setAttribute("map", map);
%>

<html>
    <head><title>test</title></head>
    <body>
        <p>Access map values by key: ${map['foo.bar']} ${map['beh.moo']}</p>

        <p>Iterate over map values:
            <c:forEach items="${map}" var="entry">
                <br>${entry.key} = ${entry.value}
            </c:forEach>
        </p>
    </body>
</html>

It works flawlessly.

BalusC
I'm not sure at all. I noticed that the 'map' field I want to access also extends HashMap<String, Object>. Maybe that could explain why it does not work.
Manuel