1

<ui:repeat> is showing a strange behaviour. I am showing some textfields and a delete link in <ui:repeat>. When delete link is clicked, the correct row is being deleted from backend, but the view still shows the deleted row, and the next row is missing instead.

Code:

<h:form>
        <ui:repeat var="tarrifDetail" value="#{tarrifBean.tarrifDetails}">
        <br />
            <p:inputTextarea id="tarrifDetailName" value="#{tarrifDetail.tarrifName}" rows="2" cols="38">
                <p:watermark value="Tarrif Name" for="tarrifDetailName" />
            </p:inputTextarea>

            <p:spacer width="6" />

            <p:inputTextarea id="tarrifDetailValue" value="#{tarrifDetail.tarrifValue}"  rows="2" cols="38">
                <p:watermark value="Tarrif Value" for="tarrifDetailValue" />
            </p:inputTextarea>

            <p:spacer width="6" />

            <p:commandLink value="Delete" action="#{tarrifBean.deleteTarrifDetail(tarrifDetail)}" update="@form" />

            <br />

        </ui:repeat>
</h:form>

tarrifBean:

public void deleteTarrifDetail(TarrifDetailManagedBean detail) throws Throwable
{
    try
    {
        TarrifDetailManagerImpl.getInstance().deleteByPrimaryKey(detail.getTarrifDetailId());
        tarrifDetails.remove(detail);

        // problem is not solved even with this temp list scene part
        List<TarrifDetailBean> temp = new ArrayList<TarrifDetailBean>();
        temp.addAll(tarrifDetails);

        tarrifDetails = temp;

        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Successfully deleted tarrif detail", null));
}

When I press Delete link of first row in ui:repeat, correct element is deleted from database, and from the list(I have debugged the code), BUT in the view, first row is still being shown, and second row is deleted instead.

Zakhar
  • 605
  • 8
  • 17
  • Have you overriden the "equals" method correctly in the TarrifDetail class? or how the entity is called. Why not use a `` instead since you already use some Primefaces components? – AndaP Jan 30 '13 at 14:28
  • @AndaP `` is working fine, thanks for the push, as I completely forgot that due to tension. But the `` mystery still remains there. –  Jan 30 '13 at 14:41
  • 3
    `` of Mojarra is broken in many ways (manily related to state management). Have you tried the latest Mojarra version? It's currently 2.1.17. This problem should not occur in MyFaces or when using a sane repeater component like ``. As to the fix, theoretically the problem should be fixed if you use `process="@this"` in the delete link (it defaults to `process="@form"`, causing all input values to be processed and thus remembered in the `` state). Try it and let me know. – BalusC Jan 30 '13 at 14:50
  • @BalusC, thanks a lot for sharing info about this bug. Wasted few hours trying to figure out what I'm doing wrong. I am using Mojarra version 2.1.17 but behavior was pretty much the same. Using `` solves problem. – Zakhar Apr 19 '13 at 15:28
  • 1
    @xmapact: in 2.1.18 en 2.1.19 some more `ui:repeat` issues were fixed, related to handling of ajax requests and nested `ui:repeat`s. – BalusC Apr 19 '13 at 15:42

0 Answers0