Reputation: 3807
I'm trying to update a repeater list with AJAX based on this : How to re-render <ui:repeat> using <f:ajax render>
But the HTML list is not updated after the first load, even if the ArrayList in the ManagedBean is.
Here is what I have in my xHTML file :
<h:form>
<h:panelGroup id="messages">
<a4j:repeat var="mes" value="#{talking.listMessages}">
<h:outputText value="#{mes.sendTime}">
<f:convertDateTime type="date" pattern="dd-MM-yyyy HH:mm"/>
</h:outputText>
#{mes.content}
</a4j:repeat>
</h:panelGroup>
<a4j:commandLink action="#{talking.testAdd}">
<h:outputText value="Add Item" />
<f:ajax execute="@form" render="messages" />
</a4j:commandLink>
</h:form>
In the MB I did this simple action :
private ArrayList<Message> listMessages;
public void testAdd() {
this.listMessages.add(new Message(/* [...] */));
}
Did I miss something ?
Upvotes: 0
Views: 479
Reputation: 85779
Check the RichFaces documentation about <a4j:commandLink>
:
The component is similar to the JavaServer Faces (JSF) component, except that it includes plugged-in Ajax behavior.
Knowing this, the problem is that <f:ajax>
doesn't work with <a4j:commandLink>
. You should rewrite your code to this:
<h:form>
<h:panelGroup id="messages">
<a4j:repeat var="mes" value="#{talking.listMessages}">
<h:outputText value="#{mes.sendTime}">
<f:convertDateTime type="date" pattern="dd-MM-yyyy HH:mm"/>
</h:outputText>
#{mes.content}
</a4j:repeat>
</h:panelGroup>
<a4j:commandLink action="#{talking.testAdd}"
render="messages">
<h:outputText value="Add Item" />
</a4j:commandLink>
</h:form>
Also, make sure you're managed bean is @ViewScoped
.
Upvotes: 2