Wicket 的 MultiAutoCompleteTextField

发布于 2024-12-18 05:57:37 字数 241 浏览 0 评论 0原文

我需要一个用于 Wicket 的 AutoCompleteTextField ,它可以处理由逗号分隔的多个自动完成项目。

像这样的东西: http://digitarald.de/project/autocompleter/ 1-1/展示/美味标签/

I need an AutoCompleteTextField for Wicket which can handle several autocomplete items separated by a comma.

Something like this: http://digitarald.de/project/autocompleter/1-1/showcase/delicious-tags/

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

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

发布评论

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

评论(3

つ可否回来 2024-12-25 05:57:37

Wicket-extensions 提供自动完成功能。

添加 以同样的方式将 AutoCompleteBehavior 添加到 TextArea AutoCompleteTextField 使用它。

例如:

TextArea t = new TextArea("area", new Model());
AutoCompleteBehavior<String> b = new AutoCompleteBehavior<String>(
            StringAutoCompleteRenderer.INSTANCE){
    @Override
    protected Iterator<String> getChoices(String input) {
        return getMyListElements().iterator();
    }
};
t.setOutputMarkupId(true);
t.add(b);
add(t);

如果您使用 Maven,只需添加以下依赖项即可开始使用 wicket-extensions:

<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket-extensions</artifactId>
    <version>${wicket.version}</version>
</dependency>

编辑
看到问题是关于多自动完成文本字段,就像这个示例中的那样,您可能会发现以下链接很有用:Wicket 自动完成文本字段。其中有几个组件似乎可以满足您的需要。

您还可能会找到此讨论和<一href="http://apache-wicket.1842946.n4.nabble.com/Auto-Complete-TextField-for-selecting-multiple-values-td1876107.html" rel="nofollow">这个 Apache Wicket 用户列表很有用。您会在那里找到几个似乎也包含此组件的项目链接:interwicketWicketHub

Wicket-extensions provides autocomplete features.

Add an AutoCompleteBehavior to the TextArea in the same fashion AutoCompleteTextField uses it.

For instance:

TextArea t = new TextArea("area", new Model());
AutoCompleteBehavior<String> b = new AutoCompleteBehavior<String>(
            StringAutoCompleteRenderer.INSTANCE){
    @Override
    protected Iterator<String> getChoices(String input) {
        return getMyListElements().iterator();
    }
};
t.setOutputMarkupId(true);
t.add(b);
add(t);

If you are using Maven, just add the following dependency to start using wicket-extensions:

<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket-extensions</artifactId>
    <version>${wicket.version}</version>
</dependency>

EDIT
Seeing that the question is about Multi autocomplete textfields, like the one in this example, you might find the following link useful: Wicket auto-complete text fields. There are a couple of components in there that seem to do just what you need.

You might also find this discussion and this one in the Apache Wicket User list useful. You'll find a couple of links there to projects that seem to also have this component: interwicket and WicketHub

难理解 2024-12-25 05:57:37

我可以通过 Ajax 在 wicket 中解决该问题,如下所示

    TextArea partnersDB = new TextArea("partnersDB");
    String partnerKeeper;

    public String getPartnerKeeper() {
        return partnerKeeper;
    }
    public void setPartnerKeeper(String partnerKeeper) {
        this.partnerKeeper = partnerKeeper;
    }
    public String getMessageTypeKeeper() {
        return messageTypeKeeper;
    }
    public void setMessageTypeKeeper(String messageTypeKeeper) {
        this.messageTypeKeeper = messageTypeKeeper;
    }

    private void makePartnersAutoCompleter() {

        final List<String> allPartners = auditDAO.findAllPartnerIds();

        IAutoCompleteRenderer partnerRenderer = new AbstractAutoCompleteRenderer() {

            @Override
            protected String getTextValue(Object obj) {
                return getPartnerKeeper() + ((String) obj);
            }

            @Override
            protected void renderChoice(Object obj, Response r, String str) {
                r.write((String) obj);
            }

        };

        AutoCompleteBehavior autoCompleteBehavior = new AutoCompleteBehavior(partnerRenderer) {

            @Override
            protected Iterator<String> getChoices(String input) {
                int lastCommaIndex = input.lastIndexOf(';');
                String realInput = "";
                if (lastCommaIndex == -1) {
                    setPartnerKeeper("");
                    realInput = input;
                } else {
                    setPartnerKeeper(input.substring(0, lastCommaIndex) + ";");
                    realInput = input.substring(lastCommaIndex + 1);
                }

                List<String> completions = new ArrayList<String>();
                for (int i = 0; i < allPartners.size(); i++) {
                    String partner = allPartners.get(i);
                    if (partner.startsWith(realInput.toUpperCase()) || partner.startsWith(realInput.toLowerCase())) {
                        completions.add(partner + ";");
                    }
                }
                return completions.iterator();
            }

        };

                    partnersDB.add(autoCompleteBehavior);

    }

I could resolve the problem by Ajax in wicket as the following

    TextArea partnersDB = new TextArea("partnersDB");
    String partnerKeeper;

    public String getPartnerKeeper() {
        return partnerKeeper;
    }
    public void setPartnerKeeper(String partnerKeeper) {
        this.partnerKeeper = partnerKeeper;
    }
    public String getMessageTypeKeeper() {
        return messageTypeKeeper;
    }
    public void setMessageTypeKeeper(String messageTypeKeeper) {
        this.messageTypeKeeper = messageTypeKeeper;
    }

    private void makePartnersAutoCompleter() {

        final List<String> allPartners = auditDAO.findAllPartnerIds();

        IAutoCompleteRenderer partnerRenderer = new AbstractAutoCompleteRenderer() {

            @Override
            protected String getTextValue(Object obj) {
                return getPartnerKeeper() + ((String) obj);
            }

            @Override
            protected void renderChoice(Object obj, Response r, String str) {
                r.write((String) obj);
            }

        };

        AutoCompleteBehavior autoCompleteBehavior = new AutoCompleteBehavior(partnerRenderer) {

            @Override
            protected Iterator<String> getChoices(String input) {
                int lastCommaIndex = input.lastIndexOf(';');
                String realInput = "";
                if (lastCommaIndex == -1) {
                    setPartnerKeeper("");
                    realInput = input;
                } else {
                    setPartnerKeeper(input.substring(0, lastCommaIndex) + ";");
                    realInput = input.substring(lastCommaIndex + 1);
                }

                List<String> completions = new ArrayList<String>();
                for (int i = 0; i < allPartners.size(); i++) {
                    String partner = allPartners.get(i);
                    if (partner.startsWith(realInput.toUpperCase()) || partner.startsWith(realInput.toLowerCase())) {
                        completions.add(partner + ";");
                    }
                }
                return completions.iterator();
            }

        };

                    partnersDB.add(autoCompleteBehavior);

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