简体   繁体   English

PrimeFaces 和 SelectOneMenu 中可见的自动完成

[英]PrimeFaces and visible autocomplete in SelectOneMenu

Is there any way to achieve the following requirement:有什么办法可以达到以下要求:

  1. Use JSF with PrimeFaces,使用 JSF 和 PrimeFaces,
  2. Use a SelectOneMenu with autocomplete,使用具有自动完成功能的SelectOneMenu
  3. Make the input text visible: ie not only typing (as it is already supported), but the user should also have an visible typing field to select a given menu item.使输入文本可见:即不仅是输入(因为它已经被支持),而且用户还应该有一个可见的输入字段到 select 给定的菜单项。

I guess it should be a combination of (customized) filtering , editable input and server-side validation, but I did not find out how.我猜它应该是(自定义) filteringeditable输入和服务器端验证的组合,但我没有找到如何实现的。

The question is old of cource but it will be helpful to others so giving the answer.这个问题很老,但它会对其他人有所帮助,所以给出答案。

Yes it is possible to get them both.是的,可以同时获得它们。 Below is the example from the PrimeFaces demo for the editable combobox.以下是可编辑 combobox 的 PrimeFaces 演示示例。

<p:outputLabel for="city" value="Editable: " />
<p:selectOneMenu id="city" value="#{selectOneMenuView.city}" effect="fold" editable="true">
    <f:selectItem itemLabel="Select One" itemValue="" />
    <f:selectItems value="#{selectOneMenuView.cities}" />
</p:selectOneMenu>

You can add another attribute to this one and get the characteristics of advanced also together with the editable.您可以向该属性添加另一个属性,并获得高级特性以及可编辑特性。

<p:outputLabel for="city" value="Editable: " />
<p:selectOneMenu id="city" value="#{selectOneMenuView.city}" effect="fold" editable="true" filter="true" filterMatchMode="startsWith">
    <f:selectItem itemLabel="Select One" itemValue="" />
    <f:selectItems value="#{selectOneMenuView.cities}" />
</p:selectOneMenu>

And you are done.你完成了。 You got both.你有两个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM