选择后动态删除行
我在尝试动态删除数据表中的行时遇到问题。基于这篇文章:
有没有办法刷新当我在一个数据表中选择一行并将该特定行的对象添加到另一个数据表中后,数据表会自动生成;意思是,如果我选择“A”并点击“添加”按钮,“A”将出现在我的第二个数据表中,并且最初包含“A”的第一个数据表将刷新,并将其从表中删除。
这是我到目前为止所拥有的:
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();
}
我将之前的方法修改为 testMethod 运行应用程序后,我现在收到此错误:
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)
我添加了一个图表来阐明我想要实现的目标。我没有使用“更新”按钮来手动更新我的数据表。我实际上正在尝试执行以下操作:
- 使用 primefaces“单行选择”数据表选择一行
- ,单击添加按钮
- ,数据表会自行更新。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 AJAX 标签来实现这一点。查看 f:ajax 标签的用法。
您还可以使用 a4J:support 标签动态“更新”特定容器中的内容。 a4J:commandLink 和 a4j:commandButton 也是使用和更新内容的另一种选择。查看这些标签,因为互联网上有很多示例。顺便说一句,“a4J”标签是 RichFaces API 的一部分。
I would suggest using AJAX tags to achieve this. Look into f:ajax tag usage.
You can also use a4J:support tags to dynamically "update" content in a particular container. a4J:commandLink and a4j:commandButton are another option to use and update content as well. Look into these tags as there are numerous examples on the Internet. By the way, the "a4J" tags are part of the RichFaces API.
您所需要的只是使用 ajax。您可能希望使用内置支持 ajax 的库,例如 primefaces 和 richfaces。然后您将使用按钮的 update 属性来立即更新数据表。
All you need is using ajax.You would probably want to use a library that has a built-in support for ajax, like primefaces and richfaces.Then you would use update property of your button in order to immediate update your datatables.