1

I have an List of Items, where I want to be able to add and remove items. For that, I add the whole List in a and everytime add or remove an item, I call update from primefaces. The code looks like this:

<h:panelGroup id="group">
     <ui:repeat value="#{manager.values}" var="item">
      <p:inputText value="#{item.name}"/>
      <p:commandButton value="Remove" action="#{manager.remove(item)}" onsuccess="update_values();"/>
     </ui:repeat>
</h:panelGroup>
<p:remoteCommand update="group" name="update_values"/>
<p:commandButton value="Add" action="#{manager.newValue()}" update="group"/>

Adding works fine, but everytime I call remove, the behaviour is strange. The item, which is the most right is deleted, and the name of the others remain unchanged, even if I remove the most left item.

After some debugging, I found out that this is because of the value="#{item.name}": The item is deleted correctly, but after the deletion, the value of the fields that exist are set for the values the fields had before. So all in all, the most right field does not exist anymore, because ui:repeat has one item less, but the others get the values they had before, so it is only possible to remove the most right field.

Has anybody an hint how to solve this? One solution maybe would be to clear every field with javascript, but I'd rather like the frameworks to solve the problem than to code something myself.

4

1 回答 1

1

像这样尝试:

<p:commandButton value="Remove" action="#{manager.remove(item)}" update=":directPath:group" process="@this" />

也许按钮本身没有硬更新的事实可能是原因。

附言

<h:form>你的元素周围有一个吗?

于 2013-10-23T13:17:38.317 回答