Discussion:
wcbase:useBean within a loop
(too old to reply)
s***@perficient.com
2006-12-14 22:43:59 UTC
Permalink
WC v6.0

I'm using a wcbase:useBean tag within a <c:forEach> loop as follows:

<c:forEach var="item" items="somelist">
<wcbase:useBean id="test" classname="someCommerceClass">
<c:set value="${item.value}" property="someKey" target="${test}"/>
</wcbase:useBean>

Printed on screen: <c:out value="${test.data}"/>
</c:forEach>

Is it okay to use the <wcbase:useBean> within a loop or is there another way of accomplishing what intended above? The reason I ask is because what is printed on the screen is what was initialized during the first iteration only. It does not for the rest of the iterations.
VijayaR
2006-12-15 06:21:16 UTC
Permalink
You may want to use the Bean only conditionally like for the first iteration only, and not for rest of the iterations.
d***@blueyonder.co.uk
2006-12-15 09:21:05 UTC
Permalink
you need to use the c:remove tag just prior to the wcbase:usebean, so in this case...

<c:forEach var="item" items="somelist">
<c:remove var="test" />
<wcbase:useBean id="test" classname="someCommerceClass">
<c:set value="${item.value}" property="someKey" target="${test}"/>
</wcbase:useBean>

Printed on screen: <c:out value="${test.data}"/>
</c:forEach>

Loading...