vaadin 中的自动完成功能?

发布于 2024-10-04 16:13:00 字数 90 浏览 1 评论 0原文

我是瓦丁新手。如何对无法加载到内存中的大量数据进行自动完成(实际上,更像是谷歌建议),而是对每个关键事件执行 JPA 查询。是否可以捕获文本字段或组合框上的关键事件?

I'm new to vaadin. How do I do autocomplete (actually, more like google suggest) on a huge set of data that cannot be loaded in memory, but instead performing a JPA query on every key event. Is it possible to capture key events on a textfield or combobox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

檐上三寸雪 2024-10-11 16:13:00

您可以查看 Henrik Paul 的 SuperImmediateTextField,它是一个 Vaadin 插件,允许您设置客户端到服务器的发布延迟(以秒为单位)。从那时起,通用 Java 堆栈可以使流程尽可能顺利。缓存、JPA 请求或其他东西。几秒钟的延迟至少会稍微减轻服务器端的负载。

You could check out Henrik Paul's SuperImmediateTextField, which is a Vaadin add-on that allows you to set the client-to-server post delay in seconds. From that on it's common Java stack to get the flow as smooth as possible. Caching, JPA requests or something else. A couple of second's delay will at least slightly lessen the load to server side.

霓裳挽歌倾城醉 2024-10-11 16:13:00

如果您不想编写自定义客户端小部件或包含其他附加组件,您可以稍微调整 Vaadin 的 ComboBox 以使其从数据库加载建议。您基本上必须做三件事才能实现这一目标:

  1. 子类 com.vaadin.ui.ComboBox 并覆盖其受保护的方法
    ComboBox#buildFilter() 与您自己的实现。
  2. 实现接口 com.vaadin.data.Container.Filter 非常
    功能受限:您的过滤器只需要传输
    当前用户输入。
  3. 编写 com.vaadin.data.Container 的实现来执行
    实际的过滤逻辑。

我更详细地描述了如何做到这一点 一篇博客文章

If you don't want to write a custom client-side widget or include another add-on, you can tweak Vaadin's ComboBox a bit to make it load suggestions from the database. You basically have to do three things to achieve that:

  1. Subclass com.vaadin.ui.ComboBox and overwrite its protected method
    ComboBox#buildFilter() with your own implementation.
  2. Implement interface com.vaadin.data.Container.Filter with very
    restricted functionality: your Filter only needs to transport the
    current user input.
  3. Write an implementation of com.vaadin.data.Container that performs
    the actual filter logic.

I described how to do that in more detail in a blog post.

人间☆小暴躁 2024-10-11 16:13:00

Vaadin 自动完成插件可以实现此目的。看看这个:-https://vaadin.com/directory/component/autocomplete

下面的示例:

   Autocomplete autocomplete = new Autocomplete();

    autocomplete.setLimit(5);

    autocomplete.addChangeListener(event -> {
        String text = event.getValue();
        autocomplete.setOptions(findOptions(text));
    });

    autocomplete.addChangeListener(event -> {
        refreshContent(event.getValue());
    });

    autocomplete.addValueClearListener(event -> {
        peopleGrid.setItems(Collections.EMPTY_LIST);
    });

    autocomplete.setLabel("Find what you want:");
    autocomplete.setPlaceholder("search ...");

下面的完整代码:
相对于="nofollow noreferrer">https://github.com/vaadin-component-factory/autocomplete/blob/master/autocomplete-demo/src/main/java/com/vaadin/componentfactory/demo/AutocompleteView.java#L132< /a>

Vaadin auto-complete add-on is available to achieve this. check this out:-https://vaadin.com/directory/component/autocomplete

Example below:

   Autocomplete autocomplete = new Autocomplete();

    autocomplete.setLimit(5);

    autocomplete.addChangeListener(event -> {
        String text = event.getValue();
        autocomplete.setOptions(findOptions(text));
    });

    autocomplete.addChangeListener(event -> {
        refreshContent(event.getValue());
    });

    autocomplete.addValueClearListener(event -> {
        peopleGrid.setItems(Collections.EMPTY_LIST);
    });

    autocomplete.setLabel("Find what you want:");
    autocomplete.setPlaceholder("search ...");

Complete code below :
https://github.com/vaadin-component-factory/autocomplete/blob/master/autocomplete-demo/src/main/java/com/vaadin/componentfactory/demo/AutocompleteView.java#L132

自此以后,行同陌路 2024-10-11 16:13:00

您可能会发现这个链接很有帮助。我猜这个问题会在 6.5 中得到修复。如果您想检查的话,还有一个插件

您需要考虑这一点,尽管

字段值 -> json-> Vaadin servlet ->;服务(spring/ejb/pojo 或其他)-> JPA->查询->结果列表(最初可能很大)

,每次按键都会返回到浏览器......

考虑一下最终用户的打字速度。当第一次击键的响应从服务器返回时,用户可能已经完成了整个单词。

You may find this link helpful. I guess this is getting fixed in 6.5. There is also an addon if you want to check.

you need to consider this though

field value -> json -> vaadin servlet -> service (spring/ejb/pojo or whatever) -> JPA -> query -> result list (which may be huge initially)

and this all the way back to browser for every key press...

think about the end user's typing speed. By the time 1st keystroke's response comes back from the server, user might have completed the whole word.

梦中楼上月下 2024-10-11 16:13:00

即时 TextField 应该就是您正在寻找的内容。看一下采样器演示:
http://demo.vaadin.com/sampler/#TextFieldTextChangeEvent

The instant TextField should be what you are looking for. Take a look at the Sampler demo:
http://demo.vaadin.com/sampler/#TextFieldTextChangeEvent

长不大的小祸害 2024-10-11 16:13:00

也许签出这个插件: https://vaadin.com/directory#!addon/suggestbox-附加组件

附带:

服务器通信延迟,例如等待用户完成n毫秒的输入

占位符文本,例如“在此处键入您的查询”

查询服务器的输入的最小长度

maybe checkout this addon: https://vaadin.com/directory#!addon/suggestbox-add-on

comes with:

delay for server communication, e.g. wait till user finished typing for n miliseconds

placeholder text like 'type your query here'

minimum length for input to query the server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文