I am facing some problems updating datatable with commandButton. This is the xhtml file:
<div class="grid_16"> <h:form id="list"> <p:messages></p:messages> <p:dataTable styleClass="result-table" var="user" id="usersList" value="#{listUsersController.users}" widgetVar="userTable" paginator="true" rows="10" paginatorAlwaysVisible="false"> <f:facet name="header"> Listado de usuarios </f:facet> <p:column> <f:facet name="header"> <h:outputText value="#{cms['users.username']}" /> </f:facet> #{user.username} </p:column> <p:column> <f:facet name="header"> <h:outputText value="#{cms['users.name']}" /> </f:facet> #{user.name} </p:column> <p:column> <f:facet name="header"> <h:outputText value="#{cms['users.lastname']}" /> </f:facet> #{user.lastname} </p:column> <p:column> <f:facet name="header"> <h:outputText value="#{cms['users.active']}" /> </f:facet> #{user.active} </p:column> <p:column> <f:facet name="header"> <h:outputText value="#{cms['general.actions']}" /> </f:facet> <p:commandButton value="Eliminar" image="ui-icon-trash" actionListener="#{listUsersController.deleteUser}" update="list:usersList"> <f:param name="user" value="#{user.id}" /> </p:commandButton> </p:column> </p:dataTable> </h:form> </div>
The problem is when you press the commandButton button, which performs the listUsersController.deleteUser action. The method completed successfully and the user was deleted. But the data is not updated. I want the remote entry to no longer appear in the list using ajax.
I already tested with update="@form" , update="@parent" , update="@all" , update="usersList" , update=":list:usersList" and nothing works.
This is the method in managedBean:
public String deleteUser() { try { FacesContext fc = FacesContext.getCurrentInstance(); Map<String, String> params = fc.getExternalContext().getRequestParameterMap(); int id = Integer.parseInt(params.get("user")); userService.removeUserById(id); FacesContext.getCurrentInstance().addMessage (null,new FacesMessage(FacesMessage.SEVERITY_INFO,MessageProvider.getMessageProvider() .getValue("cms","users.error.userDoesNotExist"),"")); return SUCCESS; } catch (EntityNotFoundException e) { FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MessageProvider .getMessageProvider().getValue("cms","users.error.userDoesNotExist"),"")); return ERROR; } }
source share