简体   繁体   中英

ATG ForEach nested map display

I was trying to display nested map data based on a Map(String, Pojo) structure. I have tried all different sorts of ways to get this to display but it will not recognize the Map object on the pojo.

            <dsp:droplet name="ForEach">
            <dsp:param name="array" bean="OrderInfo.sharedOfferInfo.parentDataMap"/>
            <dsp:oparam name="output">
            <dsp:getvalueof param="element.offersMap" var="offersMap" />
                <tr>
                    <td><p><dsp:valueof param="key" /> </p></td>
                    <dsp:droplet name="ForEach">
                        <dsp:param name="array" value="${offersMap}"/>
                        <dsp:oparam name="output">
                            <td><p><dsp:valueof param="element.description"/></p></td>
                            <td><p><dsp:valueof param="element.sku"/></p></td>
                        </dsp:oparam>
                    </dsp:droplet>
            </dsp:oparam>
            </dsp:droplet>

I have getter methods for everything so that's not the case. Do nested ForEach droplets just not work at all? I'm at a loss here.

I have tried printing out what's in the "element.offersMap" object but it just prints an empty space. If I debug the data, it's all properly populated so that's not the issue either. Will I have to create a custom droplet and return specific pieces?

Even though the main issue is resolved, the answer is for the Nested ForEach Droplet Question. When you are dealing with Nested ForEach, Try to use elementName property instead of using element which holds the current element.

element (From ORACLE ATG Docs)

Set to the current array element each time the index increments and the output parameter is rendered.

elementName

The optional parameter that should be used for the name of the element which is bound into the scope of the output oparam.

<dsp:droplet name="ForEach">
<dsp:param name="array" bean="OrderInfo.sharedOfferInfo.parentDataMap"/>
<dsp:param name="elementName" value="offers"/>
     <dsp:oparam name="output">
         <tr>
            <td><p><dsp:valueof param="key" /> </p></td>
            <dsp:droplet name="ForEach">
            <dsp:param name="array" param="offers.offersMap"/>
            <dsp:param name="elementName" value="offerMapValue"/>
                <dsp:oparam name="output">
                    <td><p><dsp:valueof param="offerMapValue.description"/></p></td>
                    <td><p><dsp:valueof param="offerMapValue.sku"/></p></td>
                </dsp:oparam>
           </dsp:droplet>
 </dsp:oparam>
</dsp:droplet>    

i suppose that parentDataMap is a map. if you want to display values of this map try this :

<dsp:droplet name="ForEach">
        <dsp:param name="array" bean="OrderInfo.sharedOfferInfo.parentDataMap.values"/>

....

Ah this question should be removed honestly. I just solved it using JSTL instead.

The parent map was returning data properly, the issue was it wouldn't give me a value for element.offersMap no matter what I did.

I implemented the same thing using JSTL and it worked fine:

<c:forEach items="${OrderInfo.sharedOfferInfo.parentDataMap}" var="entry">
    <tr><td colspan="5"><p><c:out value="${entry.key}"/></p></td></tr>
    <c:forEach items="${entry.value.offersMap}" var="entry2">
        <c:forEach items="${entry2.value}" var="entry3">
            <tr>
                <td></td>
                <td><p><c:out value="${entry2.key}" /></p></td>
                <td class="Text-Left"><p><c:out value="${entry3.description}" /></p></td>
                <td><p><c:out value="${entry3.sku}" /></p></td>
            </tr>
        </c:forEach>
    </c:forEach>
</c:forEach> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM