Abdullah Feroz
Abdullah Feroz

Reputation: 109

Primefaces autoComplete change separator

I am using primefaces autoComplete in my JSF page. The separator which it uses is comma. I am splitting the data to convert data of autoComplete to Array. Now issue is that my dataitems in autoComplete contains ", ". When I use Split in my data item, then it splits my data to. For example:

[mydataitem1, mydataitem 2, mydataitem, 3 ,.....] Now Array becomes

mydataitem1 mydataitem 2 mydataitem 3 ...

<p:autoComplete id="someId" multiple="true" value="${someBean.SomeValue}"
    completeMethod="${someBean.completeMethod}" var="value"
    itemLabel="value" itemValue="#{title}" forceSelection="true">
    <p:column>
        <h:outputText  value="#{title}" />
    </p:column>
    <p:ajax event="itemSelect" listener="#{someBean.action}" process="@form" /> 
</p:autoComplete>

Is there any attribute of autoComplete where I can change the comma to some other character?

Thanks in advance

Upvotes: 0

Views: 754

Answers (1)

Jaqen H&#39;ghar
Jaqen H&#39;ghar

Reputation: 4345

As I understand it, you'll have to bind into a List when using multiple="true". If you just use Strings you can just bind to a List<String>, if you use a complex object you'll have to use List<MyObject> and add a converter.

Note: if you print out the list in the log, it will still write

[mydataitem1, mydataitem 2, mydataitem 3,.....]

but that's just the toString()-method that delimits with comma.

Also, you have errors in itemLabel and itemValue, and should just always use #{} instead of ${}.

And I think process="@form" can be a bit dangerous, as if you have other input components in the form that fails validation/conversion the listener will not be called. I'd just remove it (default is process="@this").

Upvotes: 1

Related Questions