I am having trouble trying to remove a row in the data table dynamically. Based on this article:
JSF 2.0 Dynamically Remove Components
Is there a way to refresh the data table automatically, after I select a row in 1 data table, and add that particular row's object into another data table; Meaning, if I select "A" and hit the "add" button, "A" appears in my 2nd data table, and my first data table that initially contains "A" refreshes , and it is removed from the table.
This is what I have so far:
Index.xhtml
<p:column> <h:commandLink value ="selection" action="#{usuariosGruposBean.selectionOfUserObject}">
<f:setPropertyActionListener target="#{usuariosGruposBean.user}" value="#{users}"/></h:commandLink>
</p:column>
UserGroup Bean
public void selectionOfUserObject() {
var1 = user.getId_usuario();
}
public void testMethod() {
listOfUsuarios = getListOfUsuarios();
listOfUserGroups = getListOfUserGroups();
selectionOfUserObject();
if(listOfUsuarios.get(var1).equals(listOfUserGroups.get(var1))) {
removeUsuarios();
}
else {
System.out.println("Did not work");
}
}
}
public void finishAddUsuariosGrupos() {
this.grps = grpDAO.getGrps(var2);
this.user = userDAO.getUsuarios(var1);
this.userGroups.setId_grupo(var2);
this.userGroups.setId_usuario(var1);
this.userGroups.setGroup(grps);
this.userGroups.setUser(user);
userGrpDAO.saveUsuariosGrupos(userGroups);
testMethod();
}
I modified my previous method to testMethod After running the application, I get this error now:
WARNING: #{usuariosGruposBean.finishAddUsuariosGrupos}: java.lang.IndexOutOfBoundsException: Index: 125, Size: 3
javax.faces.FacesException: #{usuariosGruposBean.finishAddUsuariosGrupos}: java.lang.IndexOutOfBoundsException: Index: 125, Size: 3
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:636)
I have added a diagram to clarify what I am trying to achieve. I am not using an "update" button to manually update my data table. I am actually trying to do the following:
- selecting a row using primefaces "single row selection" data table
- click on add button
- the data table updates itself.