I have a primefaces datatable, where I added an empty line to the end. I would like to add a new empty line automatically when the last line was modified. I put the logic to the onRowEdit listener, but the datatable is not updated with the new empty line. (with a separate commandbutton it works, but I would like to do it automatically)
<p:dataTable id="categoryTable" var="category" value="#{categoryController.categories}" editable="true">
<p:ajax event="rowEdit" listener="#{categoryController.onRowEdit}" />
<p:ajax event="rowEditCancel" listener="#{categoryController.onRowCancel}" />
<p:column headerText="Category" sortBy="#{category.name}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{category.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="categoryName" value="#{category.name}" style="width:96%" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
.
@Named("categoryController")
@ViewScoped
public class CategoryController {
private List<Category> categories;
@EJB
CategoryEjb categoryEjb;
@PostConstruct
public void init() {
categories = categoryEjb.getAllCategory();
//add new row
categories.add(new Category());
}
public void onRowEdit(RowEditEvent event) {
Category category = (Category) event.getObject();
if (categories.indexOf(category) == categories.size()-1) {
categoryEjb.addCategory(category);
//add new row
categories.add(new Category());
} else {
categoryDao.editCategory(category);
}
}
...
}
I tried to add update="categoryForm:categoryTable"
to <p:ajax event="rowEdit">
or
RequestContext context = RequestContext.getCurrentInstance();
context.update("categoryForm:categoryTable");
to the onRowEdit
listener without success.