<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Autocomplete ignores itemValue attribute</title><link>https://answers.axonivy.com/questions/262/autocomplete-ignores-itemvalue-attribute</link><description>&lt;p&gt;I'd like to build an input field with the autocomplete widget, so the user can search for one of our dealer locations.&lt;/p&gt;
&lt;p&gt;To do this, I've created a class &lt;strong&gt;Dealer&lt;/strong&gt; and a class &lt;strong&gt;AutocompleteSource&lt;/strong&gt; which should provide the data structure and the data itself. They look like this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AutocompleteSource.java&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package ch.company.ivy.investitionsantrag;

import java.util.ArrayList;
import java.util.List;

import ch.company.ivy.investitionsantrag.Dealer;
import ch.ivyteam.ivy.environment.Ivy;

import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPSearchException;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope;

public class AutocompleteSource {
    public LDAPConnection ldapServer;

    public AutocompleteSource() throws LDAPException {
        this.ldapServer = new LDAPConnection(Ivy.var().get("LDAPHost"), Integer.parseInt(Ivy.var().get("LDAPPort")));
        ldapServer.bind(Ivy.var().get("LDAPUser"), Ivy.var().get("LDAPPassword"));
    }

    public List&amp;lt;Dealer&amp;gt; searchDealers(String query) throws LDAPSearchException {
        List&amp;lt;Dealer&amp;gt; dealers = new ArrayList&amp;lt;Dealer&amp;gt;();
        SearchResult searchResult = this.ldapServer.search("dc=COMPANY,dc=CH", SearchScope.SUB, "(&amp;amp;(|(imDealerNetwork=CHE001)(imDealerNetwork=CHE017)(imDealerNetwork=CHE003)(imDealerNetwork=CHE010))(|(cn=*" + query + "*)(imCity=*" + query + "*)))");

        for (SearchResultEntry entry : searchResult.getSearchEntries()) {
             dealers.add(new Dealer(entry.getAttributeValue("cn"), entry.getAttributeValue("imCity")));
         }

        return dealers;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Dealer.java&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package ch.company.ivy.investitionsantrag;

public class Dealer {
    public String id;
    public String city;
    public String label;

    public Dealer(String id, String city) {
        id = id.replaceFirst("^0+(?!$)", "");
        this.id = id;
        this.city = city;
        this.label = id + " " + city;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I've created a method &lt;strong&gt;dealers&lt;/strong&gt; which takes the query string and executes the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import ch.company.ivy.investitionsantrag.*;
AutocompleteSource source = new AutocompleteSource();
in.dealers = source.searchDealers(in.query);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally, my call of the autocomplete in the view:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;p:autoComplete id="dealer" completeMethod="#{logic.dealers}" required="false" var="dealer" itemLabel="#{dealer.label}" itemValue="#{dealer.id}" forceSelection="true" value="#{data.dealer}" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The autocomplete works, it takes the query and gets the results from the LDAP server. But when I select one of the suggestions it puts the whole label into the input field instead of only the id. Am I doing something wrong?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I just noticed that it in fact does use the value specified in &lt;strong&gt;itemValue&lt;/strong&gt; - it's just in the background. Anyway to tell primefaces to make the visible value in the input field the same as in the background?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/262/autocomplete-ignores-itemvalue-attribute" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 20 Jan 2014 10:08:09 -0500</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/262/autocomplete-ignores-itemvalue-attribute/271</link><description>&lt;p&gt;&lt;code&gt;itemLabel&lt;/code&gt; specifies what is displayed in the list and in the input field. If you want to have different entries in the autocomplete list than in the input field you can specify &lt;code&gt;&amp;lt;p:column&amp;gt;&lt;/code&gt; child elements to specify the list entries. 
See also the primefaces demo &lt;a href="http://www.primefaces.org/showcase/ui/autoCompletePojo.jsf"&gt;AutoComplete - Pojo&lt;/a&gt; the field "Custom Content" shows a list of players inclusive their image. If you select one then only the name is written in the text field.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Mon, 20 Jan 2014 10:08:09 -0500</pubDate><guid>https://answers.axonivy.com/questions/262/autocomplete-ignores-itemvalue-attribute/271</guid></item></channel></rss>