如何在 PrimeFaces 的芯片中使用属性自动完成

How to use attribute autocomplete in chips in PrimeFaces

我在 primefaces 中有一个 chips 标签,它有自动完成属性,但我不知道如何使用它作为建议。 请参阅下面的代码

<p:chips id="chips" value="#{partner.listString}" autocomplete="how to use auto complete here">
    <p:ajax event="itemSelect" update="itemList"/>
    <p:ajax event="itemUnselect" update="itemList"/>
</p:chips>

这是我的期望。但我不知道该怎么做?

[link 展示]https://www.primefaces.org/showcase/ui/input/chips.xhtml

如果您使用的是 JSF 2.2,则可以使用 JSF Passthrough 属性。

首先在 XHTML 文档的顶部声明命名空间 pt。

xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"

然后在您的筹码中将 pt: 添加到属性中。

<p:chips id="chips" pt:autocomplete="how to use auto complete here">

您可能正在寻找 multiple=true 的自动完成组件:https://www.primefaces.org/showcase/ui/input/autoComplete.xhtml

您所指的 autocomplete 属性是 javax.faces.component.html.HtmlInputText. From Mozilla Developer documentation 的 属性:

The source of the suggested values is generally up to the browser; typically values come from past values entered by the user, but they may also come from pre-configured values. For instance, a browser might let the user save their name, address, phone number, and email addresses for autocomplete purposes. Perhaps the browser offers the ability to save encrypted credit card information, for autocompletion following an authentication procedure.

但我认为它实际上并没有用在 Chips 组件中,但是@melloware 为您提供了使用 passthrough 属性的解决方法。

基本上,Chips 是一个免费的单词选择器,您可以在其中输入所有以列表形式表示的单词(在 conversion/validation 之后)。而自动完成组件是基于开发者定义的预设列表。根据你想做什么,@melloware 和@tandraschko 给了你正确的答案 ;)