Christian
Christian

Reputation: 395

PrimeFaces and visible autocomplete in SelectOneMenu

Is there any way to achieve the following requirement:

  1. Use JSF with PrimeFaces,
  2. Use a SelectOneMenu with autocomplete,
  3. Make the input text visible: i.e. not only typing (as it is already supported), but the user should also have an visible typing field to select a given menu item.

I guess it should be a combination of (customized) filtering, editable input and server-side validation, but I did not find out how.

Upvotes: 4

Views: 5632

Answers (1)

NickyPatel
NickyPatel

Reputation: 555

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.

<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.

Upvotes: 4

Related Questions