So I know what my problem is, I just don't know how to get around it.
I have a shopcart that allows the user to update quantity, pretty straightfoward.
<h:form >
<h
ataTable var="item" value="#{shopCartBean.orderItems}">
<h:column>
<f:facet name="header">
<h
utputText value="Product"/>
</f:facet>
<h
utputText value="#{item.productName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h
utputText value="Price"/>
</f:facet>
<h
utputText value="#{item.unitPrice}"/>
</h:column>
<h:column>
<f:facet name="header">
<h
utputText value="quantity"/>
</f:facet>
<h:inputText value="#{item.quantity}" required="true" />
</h:column>
<h:column>
<f:facet name="header">
<h
utputText value="Total"/>
</f:facet>
<h
utputText value="#{item.totalPrice}" />
</h:column>
</h
ataTable>
<h:commandButton value="update" action="#{shopCartBean.updateCart}" />
</h:form>
Problem is, if they update the quantity to zero, I want to take that item out of the cart. So I do it like this...
public
String updateCart() {
Iterator it = orderItems.iterator();
while (it.hasNext()) {
OrderItem oi = (OrderItem) it.next();
if (oi.getQuantity() == 0)
orderItems.remove(oi);
}
return "review";
}
Which throws a
java. util. Concurrent ModificationException I gather because
JSF is messing with the list while I'm removing it. I made orderItems a synchronizedList, didn't help at all.
Any ideas for a work around?
Thanks,
Dennis
[ February 27, 2006: Message edited by: Dennis Black ]