Java – JSTL where the element name contains a space character

javajspjstl

I have an array of values being made available, but unfortunately some of the variable names include a space. I cannot work out how to simply output these in the page. I know I'm not explaining this well (I'm the JSP designer, not the Java coder) so hopefully this example will illustrate what I'm trying to do:

<c:out value="${x}"/>

outputs to the page (artificially wrapped) as:

{width=96.0, orderedheight=160.0, instructions=TEST ONLY. This is a test.,
 productId=10132, publication type=ns, name=John}

I can output the name by using

<c:out value="${x.name}"/>

no problems. The issue is when I try to get the "publication type"… because it has a space, I can't seem to get <c:out> to display it.

I have tried:

<!-- error parsing custom action attribute: -->
<c:out value="${x.publication type}"/>
<!-- error occurred while evaluating custom action attribute: -->
<c:out value="${x.publication+type}"/>
<!-- error occurred while parsing custom action attribute: -->
<c:out value="${x.'publication type'}"/>
<!-- error occurred while parsing custom action attribute: -->
<c:out value="${x.publication%20type}"/>

I know the real solution is to get the variable names formatted correctly (ie: without spaces) but I can't get the code updated for quite a while. Can this be done? Any help greatly appreciated.

Best Solution

Have you tried:

<c:out value="${x['publication type']}"/>

I am assuming that a Map is the Java type behind this.