我对Wicket 8 ModalWindow返回值有问题,我引用了Modal window,它工作正常。 我将PageableListView添加到实例(请参见Pageables Example),并且工作正常。 为了使用DATABASE数据,我使用IModel进行数据查询。我没有在首页上设置查询条件,它们都可以正常工作。 但是,当我通过模式窗口将值传递回PageableListView时,NullPointerException将出现在模式窗口中。 提前致谢。 这是我的代码 ListModalTab.java
public class ListModalTab extends BasePage {
private static final long serialVersionUID = 1L;
@SpringBean
private TabHService oTabHService_;
private PageableListView cTabHListView_;
public ListModalTab() {
final Form cForm = new Form("form");
final Label result;
cForm.add(result = new Label("result", new PropertyModel<>(this, "result")));
result.setOutputMarkupId(true);
final ModalWindow modal1;
cForm.add(modal1 = new ModalWindow("modal1"));
modal1.setCookieName("modal-1");
modal1.setPageCreator(() -> new QueryModalTab(ListModalTab.this.getPageReference(), modal1));
modal1.setWindowClosedCallback(target -> target.add(cForm));
modal1.setOutputMarkupId(true);
modal1.setCloseButtonCallback(target -> {
setResult("Modal window 1 - close button");
return true;
});
cForm.add(new AjaxLink<Void>("showModal1") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
modal1.show(target);
}
});
final WebMarkupContainer cContainer = new WebMarkupContainer("container");
cContainer.setOutputMarkupId(true);
cForm.add(cContainer);
/*
* Data query using IModel
*/
TabH oConstraintEntity = new TabH();
IModel mTabHListViewModel = new Model() {
public java.io.Serializable getObject() {
return (Serializable) oTabHService_.queryByTabH(oConstraintEntity);
}
};
/*
* Use string array data
*/
//final String[] names = { "Doe, John", "Presley, Elvis", "Presly, Priscilla",
// "Hasselhoff, David", "Moore, Demi", };
/*
* PageableListView is working properly if used with string array
*/
// PageableListView<String> listview = new PageableListView<String>("rows", Arrays.asList(names), 1) {
// @Override
// protected void populateItem(ListItem<String> item) {
// item.add(new Label("tabId", item.getModelObject()));
// }
// };
/*
* If the PageableListView is passed in using an IModel Object, the modal window will have a NullPointerException.
*/
PageableListView<TabH> listview = new PageableListView<TabH>("rows", mTabHListViewModel, 1) {
@Override
protected void populateItem(ListItem<TabH> item) {
final TabH oTabH = (TabH) item.getModelObject();
item.add(new Label("tabId", oTabH.getTabId()));
}
};
cContainer.add(listview);
cContainer.add(new AjaxPagingNavigator("navigator", listview));
this.add(cForm);
}
/**
* @return the result
*/
public String getResult() {
return result;
}
/**
* @param result
* the result to set
*/
public void setResult(String result) {
this.result = result;
}
private String result;}
QueryModalTab.java
public class QueryModalTab extends WebPage {
private static final long serialVersionUID = 1L;
private TabH tabH = new TabH();
public QueryModalTab(final PageReference modalWindowPage, final ModalWindow window) {
CompoundPropertyModel mTabH = new CompoundPropertyModel(tabH);
Form cForm = new Form("form", mTabH);
TextField cTabId = new TextField("tabId");
cForm.add(cTabId);
TextField cTabName = new TextField("tabName");
cForm.add(cTabName);
cForm.add(new AjaxLink<Void>("closeOK") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (modalWindowPage != null)
((ListModalTab) modalWindowPage.getPage()).setResult("Modal window 1 - close link OK");
window.close(target);
}
});
/*
* NullPointerException appears in ((ListModalTab) modalWindowPage.getPage())
*/
AjaxSubmitLink cConfirm = new AjaxSubmitLink("confirm") {
@Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
if (modalWindowPage != null)
((ListModalTab) modalWindowPage.getPage()).setResult(tabH.getTabId());
ModalWindow.closeCurrent(target);
}
};
cForm.add(cConfirm);
cForm.add(new AjaxLink<Void>("closeCancel") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
if (modalWindowPage != null)
((ListModalTab) modalWindowPage.getPage()).setResult("Modal window 1 - close link Cancel");
window.close(target);
}
});
this.add(cForm);
}
}
NullPointerException
Root cause:
java.lang.NullPointerException
at com.web.webpage.systempage.tab.QueryModalTab$2.onSubmit(QueryModalTab.java:52)
at org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink$1.onSubmit(AjaxSubmitLink.java:111)
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$AjaxFormSubmitter.onSubmit(AjaxFormSubmitBehavior.java:223)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1251)
at org.apache.wicket.markup.html.form.Form.process(Form.java:946)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:770)
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:176)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:151)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:598)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.internalInvoke(ListenerRequestHandler.java:306)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.invoke(ListenerRequestHandler.java:280)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.invokeListener(ListenerRequestHandler.java:222)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.respond(ListenerRequestHandler.java:208)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:912)
at org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:65)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:283)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:253)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:221)
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:262)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:204)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:286)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)