wrong row deleted in datatable
wschung Dec 31, 2007 10:25 AMI am trying to create a datatable with a delete link in one of the datatable column, using rowKeyVar to label the row index in the link. After I added two rows and click the delete link on the first row, the second row is deleted. I can see the values that the action listener picks up is correct. Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:authz="http://sourceforge.net/projects/jsf-comp/acegijsf">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Edit Rich Order</title>
</head>
<body>
<ui:composition>
<f:view>
<f:verbatim><h1>Create An Order</h1></f:verbatim>
<h:messages showDetail="true" showSummary="false"/>
<h:form>
<h:commandButton value="Add Line Item" action="#{order.addItem}" immediate="true"/>
<rich:dataTable value="#{order.lineItems}" var="item" rowKeyVar="rowId">
<rich:column>
<f:facet name="header">
<t:outputText value="ID"/>
</f:facet>
<t:inputText value="#{item.id}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<t:outputText value="Product Name"/>
</f:facet>
<t:inputText value="#{item.productName}"/>
</rich:column>
<rich:column>
<t:commandLink action="#{order.removeItem}" immediate="true">
<f:verbatim>Remove</f:verbatim>
<f:param name="id" value="#{rowId}"/>
</t:commandLink>
</rich:column>
</rich:dataTable>
</h:form>
<t:saveState value="#{order}"/>
</f:view>
</ui:composition>
</body>
</html>Order.removeItem():
public String removeItem(){
String value = (String) FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("id");
int index = Integer.parseInt(value);
lineItems.remove(index);
return "success";
}I saw the same problem with tomahawk. The example is adapted from tomahawk code. Am I missing something?