Search code examples
ajaxjsfjsf-2richfaces

a4j:poll - reloading data model


I'm trying to use a4j:poll component for ajax reloading a datatable after some time interval. It's working fine, but when the table is automatically reloaded and I use the tools (edit/delete row) in the last column, datatable (all the rows) disappears and I have to load it manually (using h:commandButton)..

Here's part of my code:

<h:form>
  <a4j:poll id="poll" interval="30000" action="#{bean.load}" enabled="#{bean.pollEnabled}" render="list" />
</h:form>

<h:form id="list" ...>
 <rich:dataTable id="table" var="item" value="#{bean.model}">
 ...

A button which is calling the same load method:

  <h:commandButton id="btn" action="#{bean.load}" ... /> 

When I reload it using button, I can use the tools in the last column. Don't you know why?

enter image description here

UPDATE:

  • seems that in first case (a4j:poll), when using edit/delete, constructor of the bean is called........
  • bean is @ViewScoped

Solution

  • seems that in first case (a4j:poll), when using edit/delete, constructor of the bean is called

    I don't do RichFaces, but I guess that this problem is in some way related to JSF issue 790 which causes the view state of other forms being lost during ajax requests initiated by a separate form (and indeed also causes reconstruction of the backing beans associated with the other forms). This is also described as point 7 of commandButton/commandLink/ajax action/listener method not invoked or input value not updated.

    In your particular case, placing the <a4j:poll> in the same form as the table should solve the problem. I'm not sure why that was placed in a separate form in first place, but that seems just unnecessary.