5 Replies Latest reply on Feb 21, 2012 11:56 AM by Maheswara Sunkara

    Autocomplete and returning the id

    Mette Hummel Newbie

      We are using RichFaces 4 and autocomplete.


      We want to show a description in the autocomplete field but want to return the id to the backingBean. The id is part of the object I pass to the autocomplete. How do I do this?

        • 1. Re: Autocomplete and returning the id
          jlpktnst Newbie

          Same question here, want to bind 2 different values, hidden id and display the text. User searches by text, but the codebehind needs id.


          Doable? Right now I have a workaround which is quite bad, got id in field and a separate ajax lookup for description. But that is not good.

          • 2. Re: Autocomplete and returning the id
            Christian Peter Expert

            You can use rich:select but without (ajax) suggestion.


            Or build a converter String<->Object.


            Piggybagging the id as hidden request parameter.


            <rich:autocomplete autocompleteMethod="#{tableDemoManager.autocompleteDTO}" var="result" mode="ajax" showButton="true" layout="table" fetchValue="#{result.name}" onselectitem="doSelect(event);">


            <span data-value="#{result.name}" data-uuid="#{result.uuid}">#{result.name}</span>





            <a4j:jsFunction name="submitUUID" action="#{tableDemoManager.submitUUID}">

              <a4j:param name="uuid" assignTo="#{tableDemoManager.uuid}"/>



            function doSelect(event){

                var currentValue = event.rf.component.getValue();

                var items = event.rf.component.items;

                var item = jQuery(items).find("span[data-value='" +currentValue+"']");

                var uuid = jQuery(item).attr('data-uuid');





            • 3. Re: Autocomplete and returning the id
              jlpktnst Newbie

              This seems useful, I will try when I can.


              Another question: can I override the javascript for clientside matching when I have manual text input rich:select? I want to have containsText instead of startsWith...

              • 4. Re: Autocomplete and returning the id
                Brendan Healey Master

                RE: can I override the javascript for clientside matching w


                (a very late answer, so for the benefit of anyone else coming across this post...) you should be able to  use

                rich:autocomplete clientFilterFunction="myFilter":


                function myFilter(prefix, string) {

                  // return true on match or false





                • 5. Re: Autocomplete and returning the id
                  Maheswara Sunkara Novice

                  did you try this:


                  <rich:autocomplete mode="ajax" showButton="true" layout="table" autocompleteMethod="#{patientSearch.searchPatientByAll}"

                  fetchValue="#{patient.patientId}" id="txtPatientSearch" var="patient">
                  <h:outputText value="#{patient.name}" />

                  <h:outputText value="#{patient.gender}" />


                  This shows name and gender in the autocomplete field and returns id to the backing bean...