Wicket:延迟加载 DropDownChoice [英] Wicket: Lazy loading DropDownChoice

查看:16
本文介绍了Wicket:延迟加载 DropDownChoice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 web 应用程序上的一个 DropDownChoice 列表需要很长时间才能创建,因为通过 LDAP 连接和 SQL 连接的某些操作获取选项.正因为如此,整个页面的加载时间远远超过几秒钟 - 我会说太多了.

One DropDownChoice list on my webapp takes very long time to create, because of getting options by some operations with LDAP connection and SQL connection. And because of that the whole page is loading much more than a couple of seconds - I'd say too much.

所以我想要实现的是使用(最适合我)Wicket 的内置 Ajax 功能来延迟加载这个下拉列表,但我有一些问题.

So what I want to achieve, is to use (best for me) the built-in Ajax functionality of Wicket to lazy load this dropdown, but I have some problems.

我知道如何制作常规的 DropDownChoice 列表,这个简单的例子对我很有用 - 链接

I know how to make regular DropDownChoice list, this simple example working great for me - link

我也知道如何制作延迟加载的段落,来自 wicket-examples - link(源代码 -> LazyLoadingPage.html/LazyLoadingPage.java)

I also know how to make lazy-loaded paragraph, from wicket-examples - link (Source Code -> LazyLoadingPage.html/LazyLoadingPage.java)

但是把它放在一起会抛出异常并导致 Wicket 的内部错误.

But putting it together throwing me exceptions and resulting Wicket's Internal error.

这是我尝试这样做的方法:

Here is how I try to do it:

在 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 收到内部错误,并在日志中:

And I'm getting Internal Error from Wicket, with that in logs:

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,当前 = ''

, index = 0, current = ''

和堆栈跟踪.

我真的很感激一些帮助,我做错了什么,或者一些更好的代码示例.

I would really appreciate some help, what I'm doing wrong, or maybe some better code examples.

推荐答案

感谢 bert,我把它放在这里完整的解决方案,以防将来有人使用它.

Thanks to bert, I'm putting here full solution, in case someone will use it in the future.

我们需要创建自己的面板,因为 AjaxLazyLoadPanel 只能将一个面板更改为另一个.

We need to create our own panel, because AjaxLazyLoadPanel can only change one panel to another.

MyPanel.html 示例:

Example of MyPanel.html:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
    <select wicket:id="project"></select>
</wicket:panel>
</body>
</html>

和 MyPanel.java :

and MyPanel.java :

public class MyPanel extends Panel {
    private String selected = <what you want>;
    private List<String> projectList <what you want>;
    public MyPanel(String id) {
        super(id);
        add(new DropDownChoice<String>(
           "project", new PropertyModel<String>(this, "selected"), projectsList));
    }
}

在您的主页 html 上简单地添加:

On your main page html simply add this:

<span wicket:id="lazy2"></span>

在主页java文件中:

and in main page java file:

add(new AjaxLazyLoadPanel("lazy") {
    @Override
    public Component getLazyLoadComponent(String id) {
        return new MyPanel(id);
    }
});

希望它也能帮助其他人:-)

Hope it will help someone else too :-)

这篇关于Wicket:延迟加载 DropDownChoice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆