Today I added a feature in my shopping cart JSP page but nothing was showing up. This was because the output of ATG ForEach droplet was blanks.
To debug this I did the following steps.
- I added an empty oparam to see if the ForEach droplet thought the collection was empty.
<dsp:oparam="empty">Empty?</dsp:oparam>
It did not.
- I outputted the count in the output oparam to see if it was looping through the collection.
<dsp:oparam="output"><dsp:valueof param="count"/> <dsp:valueof param="element"/></dsp:oparam>
It was looping through the collection.
- Finally I debugged using Eclipse the ForEach code. The ForEach code can be found in <ATG>/DAS/src/Java/atg/droplet/ForEach.java.
Using the debugger I realized that the element name of the loop was being set to something else which is why <dsp:valueof param=â€elementâ€/> was blank.
It turned out that the ForEach droplet was inside another ForEach droplet and in that droplet they set the element name like this.
<dsp:param name="elementName" value="CommerceItem" />
By setting the elementName parameter to something else in my ForEach droplet and then referencing it properly I was finally able to get the expected output.
<dsp:droplet name="/atg/dynamo/droplet/ForEach"> <dsp:param name="array" param="CommerceItem.auxiliaryData.productRef.dvds"/> <dsp:param name="elementName" value="dvd" /> <dsp:oparam name="output"> <dsp:valueof param="dvd.name" /> </dsp:oparam> </dsp:droplet>
By the way ATG documentation suggests not using elementName.
elementName
andindexName
allow you to provide a parameter name other thanelement
andindex
, respectively. A better way to provide a different parameter name is to use thedsp:setvalue
tag.
In our example we would do this instead of setting the elementName param.
<dsp:setvalue param="dvd" paramvalue="element" />