我在每行都有一个带有ajax链接的列表。此链接管理自己的行删除过程。用WebMarkupContainer包装的整个列表。 通过按下链接,调用下一个逻辑 1)从DB中删除的项目。 2)更新列表模型 3)target.add(wmc) - 将WebMarkupContainer添加到ajax进行更新
因为list有多个元素,每个删除动作在渲染阶段崩溃。因此,在刷新页面后,我看到该操作已完成,但在此之后发生了问题
IKickListener onKickListener = new IKickListener() {
@Override
public void onKickListener(ListItem<Consultant> item, AjaxRequestTarget target) {
Cons modelObject = item.getModelObject();
mUserDAO.remove(modelObject.accountId, getId());
updateListModel();
target.add(mWmc);
target.appendJavaScript("console.log("kicked")");
}
};
mWmc = new WebMarkupContainer("wmc");
mWmc.setOutputMarkupId(true);
add(mWmc);
ListView listView = new ConsListView("consList", new PropertyModel<List<? extends Cons>>(this, "consultants"), onKickListener);
mWmc.add(listView);
并填充我的列表的方法
@Override
protected void populateItem(final ListItem<ConsPanel.Cons> item) {
item.add(new IndicatingAjaxLink("actionKick") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
mKickListener.onKickListener(item, target);
}
});
}
然后我收到了下一个堆栈跟踪
org.apache.wicket.core.request.handler.ComponentNotFoundException: Component 'consPanelPlace:cons:wmc:consList:2:actionKick' has been removed from page.
at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:177)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:865)
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我使用wicket 7.0.0-M5
更新 我发现,当我在列表中有超过1个项目时,仅为第一个附加ajax回调。但是在点击操作中删除了除一个以外的所有项另外ajax链接称为项目计数次数。
答案 0 :(得分:4)
我解决了这个问题。我有同样的id而不是wicket:id,但是每个项目的一般id。所以听众已经附加到第一个,因为wicket ajax听取了它。然后它几次打电话。 问题在于标记。
<span class="btn" wicket:id="actionKick" id="kick">Kick</span>
^^^^^^^^^---problem was here