【发布时间】:2025-12-07 02:45:01
【问题描述】:
我的 web 应用程序上的一个 DropDownChoice 列表需要很长时间才能创建,因为通过 LDAP 连接和 SQL 连接的某些操作获取选项。正因为如此,整个页面的加载时间远远超过了几秒钟——我想说的太多了。
所以我想要实现的是使用(最适合我)Wicket 的内置 Ajax 功能来延迟加载这个下拉列表,但是我有一些问题。
我知道如何制作常规的 DropDownChoice 列表,这个简单的示例对我来说非常有用 - link
我也知道如何从 wicket-examples - link (Source Code -> LazyLoadingPage.html/LazyLoadingPage.java) 制作延迟加载的段落
但是把它放在一起会抛出异常并导致 Wicket 的内部错误。
这是我尝试的方法:
在 HTML 中:
<select wicket:id="lazy"></select>
在 Java 中:
private String selected = "abc";
(...)
add(new AjaxLazyLoadPanel("lazy") {
@Override
public Component getLazyLoadComponent(String id) {
//simulating long time for simple list
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new DropDownChoice<String>(
id, new PropertyModel<String>(this,"selected"),
Arrays.asList("abc","def"));
}
});
}
我从 Wicket 收到内部错误,并在日志中显示:
ERROR Unexpected error occurred
Component [content] (path = [0:lazy:content]) must be applied to a tag of type [select], not: '<div wicket:id="content">' (line 0, column 0)
MarkupStream: [markup = jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%207.0/webapps/devservices/WEB-INF/lib/wicket-extensions-1.5.7.jar!/org/apache/wicket/extensions/ajax/markup/html/AjaxLazyLoadPanel.html
,索引 = 0,当前 = ''
和堆栈跟踪。
非常感谢一些帮助,我做错了什么,或者一些更好的代码示例。
【问题讨论】:
-
尝试将 DDC 放入面板(或片段)并在 getLazyLoadComponent() 中构造/返回它
-
@bert 你成就了我的一天!完美运行 - 非常感谢!!!
-
还可以查看 select2 wicket 实现,请参阅 github.com/ivaynberg/wicket-select2
标签: java ajax web-applications wicket