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

    Autocomplete and returning the id

    mettehummel

      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

          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
            mcmurdosound

            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);">

            <rich:column>

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

            </rich:column>

            </rich:autocomplete>

             

             

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

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

            </a4j:jsFunction>

             

            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');

                console.log(uuid);

             

                submitUUID(uuid);

            }

            • 3. Re: Autocomplete and returning the id
              jlpktnst

              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
                healeyb

                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

                }

                 

                Regards,

                Brendan.

                • 5. Re: Autocomplete and returning the id
                  sunkaram

                  did you try this:

                   

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

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

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

                   

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