Nikola Milikic created MYFACES-3939:
---------------------------------------
Summary: ui:repeat uses wrong items when the background list is
modified
Key: MYFACES-3939
URL: https://issues.apache.org/jira/browse/MYFACES-3939
Project: MyFaces Core
Issue Type: Bug
Affects Versions: 2.2.4
Environment: JSF 2.2.6
Reporter: Nikola Milikic
I use ui:repeat to display list items. But if the list is altered in a way that
element indexes are changed (for instance, an item is added to the beginning of
the list), elements inside the ui:repeat interact with the wrong items from the
list.
Here is a simple example where the list items are printed and on a mouse click,
the value is passed to a bean's method:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>
<h:form>
<ui:repeat value="#{testBeanRepeat.items}" var="item">
<h:commandLink value="#{item}"
action="#{testBeanRepeat.click(item)}">
<f:ajax />
</h:commandLink>
<br/>
</ui:repeat>
</h:form>
</h:body>
</html>
In the background bean, a new item is added to the beginning of the list on
every 5 seconds:
@ManagedBean(name = "testBeanRepeat")
@ViewScoped
public class TestRepeatBean implements Serializable {
private static final long serialVersionUID = -770055099629687227L;
private List<String> items;
@PostConstruct
public void init() {
items = new ArrayList<String>();
items.add("item 1");
items.add("item 2");
items.add("item 3");
Timer timer = new Timer();
timer.schedule( new TimerTask() {
public void run() {
items.add(0, "item "+System.currentTimeMillis());
}
}, 0, 2000);
}
public void click(String item) {
System.out.println("Clicked on: "+item);
}
public List<String> getItems() {
return items;
}
}
If you click after 2 seconds on the first item labeled 'item 1', you will get
printed what is the first element of the list in that moment and not 'item 1',
for instance 'Clicked on: item 1414965931158'.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)