tags:

views:

44

answers:

3

I have a map declaration:

<!-- SOME MAP -->
<util:map id="someMap" map-class="java.util.HashMap" 
  key-type="java.lang.String" value-type="java.lang.String" >
     <entry key="0" value="SOME VALUE" />
 <entry key="1" value="SOME VALUE 2" />
 <entry key="default" value="SOME VALUE 3" />
</util:map>

<!-- SOME MAP REFERENCE -->
<util:map id="someMapRef" map-class="java.util.HashMap" 
  key-type="java.lang.String" value-type="java.util.HashMap" >
    <entry key="0" value ref = "someMap" />
    <entry key="default" value="SOME VALUE" />
</util:map>

What is wrong with that? Any suggestion?

A: 

Not valid XML:

<entry key="0" value ref = "someMap" />

remove "value"

gawi
I get "attribute ref is not allowed in map entry"
Milli Zeloski
+2  A: 

Firstly, the XML is not well-formed, it should be:

<entry key="0" value-ref="someMap"/>

Also, according to your definition, the someMapRef map bean can only contain values of type java.util.HashMap, but you're trying to set a value for key 0 of SOME VALUE, which is a String. It can contain Strings, or hashMaps, but not both.

skaffman
Yea, that was my typo mistake just to populate the other key-value pair.
Milli Zeloski
THANK YOU. It worked.
Milli Zeloski
A: 

I think it should work like this:

<util:map
    id="someMap"
    map-class="java.util.HashMap"
    key-type="java.lang.String"
    value-type="java.lang.String">
    <entry
        key="0"
        value="SOME VALUE" />
    <entry
        key="1"
        value="SOME VALUE 2" />
    <entry
        key="default"
        value="SOME VALUE 3" />
</util:map>


<!-- type: Map<String, Map<String, String>> -->
<util:map
    id="someMapRef"
    map-class="java.util.HashMap"
    key-type="java.lang.String"
    value-type="java.util.Map">
    <entry
        key="0"
        value-ref="someMap" /> <!-- value-ref not "value ref" -->
        <!-- This is the map constructed above -->

    <entry
        key="SOME_VALUE">
        <map> <!-- and here is another map -->
            <entry
                key="SOME_OTHER_KEY1"
                value="SOME_OTHER_VALUE1" />
            <entry
                key="SOME_OTHER_KEY2"
                value="SOME_OTHER_VALUE2" />
            <entry
                key="SOME_OTHER_KEY3"
                value="SOME_OTHER_VALUE3" />
        </map>
    </entry>
</util:map>
seanizer