a4j:repeat dos not rerender on element removal
root2000 May 2, 2007 10:45 AMHi, I have the following problem: I use a4j:repeat to dinamically populate a table, I have also implemented adding and removing buttons to dinamically add and remove rows. I have no problem when adding rows but when removing always the last row is removed when I click the minus command link. On the server-side the right element is removed. Here is the jsp:
<a4j:outputPanel id="containers">
<div class="border"
style="height: 100px; width: 250px; overflow-y: scroll; overflow-x: auto;">
<table class="normalText" border="1">
<tr>
<th class="headerCenter"></th>
<th class="headerCenter">?????</th>
<th class="headerCenter">??? ?? ??????????</th>
<th class="headerCenter"><a4j:commandLink
action="#{controlResultsController.addRow}" reRender="containers">
<h:graphicImage style="border: none" value="/images/plus.gif" />
<a4j:actionparam name="plusTable" value="containers"></a4j:actionparam>
</a4j:commandLink></th>
</tr>
<a4j:repeat value="#{goodsItemIE518.containers}" var="GIContainers">
<tr>
<td></td>
<td><h:inputText size="5" value="#{GIContainers.containerNumber}"></h:inputText></td>
<td></td>
<td><a4j:commandLink reRender="containers"
style="text-decoration : none"
action="#{controlResultsController.removeElement}">
<h:graphicImage style="border: none;" value="/images/minus.gif" />
<a4j:actionparam name="rowIndex"
value="#{ecs:countRows(goodsItemIE518.containers,GIContainers)}"></a4j:actionparam>
<a4j:actionparam name="minusTable" value="containers"></a4j:actionparam>
</a4j:commandLink></td>
</tr>
</a4j:repeat>
</table>
</div>
</a4j:outputPanel></td>[And the server-side code:
package com.itt.ecs.web.exit;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.itt.ecs.dto.common.goods.GIContainers;
import com.itt.ecs.dto.common.goods.GIPackages;
import com.itt.ecs.dto.common.goods.GIPreviousAdmReferences;
import com.itt.ecs.dto.common.goods.GIProducedDocCert;
import com.itt.ecs.dto.common.goods.GISpecialMentions;
import com.itt.ecs.dto.common.goods.GoodsItem;
import com.itt.ecs.web.AbstractFacesBean;
public class ControlResultsController extends AbstractFacesBean {
/**
*
*/
private static final long serialVersionUID = 6845108217618495706L;
private int rowIndex;
public int getRowIndex() {
return rowIndex;
}
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
/**
* removes an element from a datatable
*
* @return same url
*/
public static int getRowNumber(List listOfElements, Object element) {
int currentRow = 0;
currentRow=listOfElements.indexOf(element);
return currentRow;
}
/**
* remove element from datatable
*
* @return null
*/
public String removeElement() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context
.getExternalContext().getRequest();
String minusName = request.getParameter("minusTable");
int rowIndex=Integer.parseInt(request.getParameter("rowIndex"));
GoodsItem goodsBean = (GoodsItem) getBean("goodsItemIE518");
ArrayList goodsList;
if (minusName.equals("prevAdminDocuments")) {
goodsList = (ArrayList) goodsBean.getPrevAdminDocuments();
GIPreviousAdmReferences good = ((GIPreviousAdmReferences) goodsList
.get(rowIndex));
good.setAvailable(false);
goodsList.remove(rowIndex);
} else if (minusName.equals("producedDocCerts")) {
goodsList = (ArrayList) goodsBean.getProducedDocCerts();
GIProducedDocCert good = ((GIProducedDocCert) goodsList
.get(rowIndex));
good.setAvailable(false);
goodsList.remove(rowIndex);
} else if (minusName.equals("specialMentions")) {
goodsList = (ArrayList) goodsBean.getSpecialMentions();
GISpecialMentions good = ((GISpecialMentions) goodsList
.get(rowIndex));
good.setAvailable(false);
goodsList.remove(good);
} else if (minusName.equals("containers")) {
goodsList = (ArrayList) goodsBean.getContainers();
GIContainers good = ((GIContainers) goodsList.get(rowIndex));
good.setAvailable(false);
goodsList.remove(rowIndex);
} else if (minusName.equals("packages")) {
goodsList = (ArrayList) goodsBean.getPackages();
GIPackages good = ((GIPackages) goodsList.get(rowIndex));
good.setAvailable(false);
goodsList.remove(rowIndex);
}
setBean("goodsItemIE518", goodsBean);
return null;
}
/**
* adds a row to a table
*
* @return
*/
public String addRow() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context
.getExternalContext().getRequest();
String plusName = request.getParameter("plusTable");
GoodsItem goodsBean = (GoodsItem) getBean("goodsItemIE518");
ArrayList goodsList;
if (plusName.equals("prevAdminDocuments")) {
goodsList = (ArrayList) goodsBean.getPrevAdminDocuments();
goodsList.add(new GIPreviousAdmReferences());
} else if (plusName.equals("producedDocCerts")) {
goodsList = (ArrayList) goodsBean.getProducedDocCerts();
goodsList.add(new GIProducedDocCert());
} else if (plusName.equals("specialMentions")) {
goodsList = (ArrayList) goodsBean.getSpecialMentions();
goodsList.add(new GISpecialMentions());
} else if (plusName.equals("containers")) {
goodsList = (ArrayList) goodsBean.getContainers();
goodsList.add(new GIContainers());
} else if (plusName.equals("packages")) {
goodsList = (ArrayList) goodsBean.getPackages();
goodsList.add(new GIPackages());
}
setBean("goodsItemIE518", goodsBean);
return null;
}
}
thx in advance for the support