Search code examples
javaatgatg-droplet

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?


Solution

  • 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>