1 2 Previous Next 18 Replies Latest reply on Jun 11, 2013 10:52 AM by ibenjes

    Can I use rich:autocomplete for setting complex value?

    v_panasyuk

      I want to get data from database for autocomplete dynamically, becouse I have a lot of patients(10.000).


      <rich:autocomplete layout="table" mode="cachedAjax" minChars="1" tokens=";" autocompleteMethod="#{selectPatientManagedBean.searchByText}"
                                                 fetchValue="#{pat.name}" var="pat">
                                  <rich:column>
                                      <h:outputText value="#{pat.name}"/>
                                  </rich:column>
                              </rich:autocomplete>
      

      But patients name must be visible as selected value, and I must set to Bean. #{pat.id}!!, not name. User must not see any internal ID


      I read about rich:autocomplete as text value component...but rich:select must get all value from database for autocomplete(client side autocomplete)

       

      Please help me.

        • 1. Can I use rich:autocomplete for setting complex value?
          ilya_shaikovsky

          The only way with autocomplete - to use converter if it's possible to restore the object from the String name. It's input and not a select component. For selection (with manual input option available) you should use rich:select.

           

          We plan to add ajax mode for rich:select(currently not available) - and with enableManualInput set to true it will works as you need.

          • 2. Re: Can I use rich:autocomplete for setting complex value?
            v_panasyuk

            Thanks, and

             

            I try include to rich:autocomplete tag a4j:ajax. And I have error

            <a4j:ajax> oncompleteevent is not supported for the UIAutocomplete.

             

            I want, after select some item from autocomplete list(eg. patient), get for this patient, using AJAX, his name, age, patient number. Can I do it using RichFaces?

            • 3. Re: Can I use rich:autocomplete for setting complex value?
              ilya_shaikovsky

              use event="change"

              • 4. Can I use rich:autocomplete for setting complex value?
                v_panasyuk

                Thanks, but event "change" will executed only after I focus to other component, but I really want execute event, only after I select item from list

                • 5. Can I use rich:autocomplete for setting complex value?
                  liuliu

                  hi,

                  there is a onselect event, at least in rf 3.3 .:-)

                  • 6. Can I use rich:autocomplete for setting complex value?
                    ilya_shaikovsky

                    onselectitem present in 4.x

                     

                    but in case the user made changes in inputs and leaved the field - no submissions will be made. Is it ok in your case?

                    • 7. Can I use rich:autocomplete for setting complex value?
                      v_panasyuk

                      It is ok. But How to use it.

                      • 8. Re: Can I use rich:autocomplete for setting complex value?
                        giberius

                        I have the same problem:

                         

                        rich:select will fetch all the data from database to client, you cannot filter as it is possible with rich:autocomplete. If you have between 1000 and 10.000 records it will have a performance penalty. A filter with three characters will bring back a list of 1000 to likely a list of 10. It is "stupid" to send 1000 or 10.000 recors to the client and then to filter there with javascript.

                         

                        rich:autocomplete seems not to give the possibility to show the name and to get the id in the bean, a lookup in a converter or with the valuechangelistener on name is not possible if multiple names with different id are in the database (which is likely the case).

                         

                        So rich:select is not a good solution if you have a lot of records.

                         

                        So, autocomplete should have the possiblity to show the name and to retrieve the id. I do not share the opion that autocomplete is an input component and not a select component. Does somebody has found a solution to retrieve the id and present the name? (and not to lookup the id by means of the name because that just not always possible).

                        • 9. Re: Can I use rich:autocomplete for setting complex value?
                          mp3hifi12

                          Hello,

                           

                          I am sorry for updating  this old thread, but I have exact the same problem.

                           

                          In my Autocomplete I am searching for a company by name. When the user press Enter the selected company must be available in the backingbean. The name of the company is not enough to indentify the right company.

                           

                          Kind regards

                          • 10. Re: Can I use rich:autocomplete for setting complex value?
                            healeyb

                            Martin, surprisingly it does not seem to be possible to do this at present. rich:autocomplete is a bit of a

                            chocolate teapot. See also:

                             

                            https://community.jboss.org/message/718855#718855

                            https://issues.jboss.org/browse/RF-11453 - ** please vote for this **

                             

                            There doesn't seem to be any recognition from the dev team that the component really doesn't do anything

                            very useful at the moment, outside the most simple use cases.

                             

                            Regards,

                            Brendan.

                            • 11. Re: Can I use rich:autocomplete for setting complex value?
                              mp3hifi12

                              Hello Brendan,

                               

                              thanks very much for this hint. At the moment I am evaluating RichFaces and PrimeFaces, but with problems like this, I can shorten the period.

                               

                              Regards,

                              Martin

                              • 12. Re: Can I use rich:autocomplete for setting complex value?

                                Hi,

                                 

                                I had the same problem, try this:

                                 

                                <rich:autocomplete minChars="1" valueChangeListener="#{bean.valueChange}"
                                    autocompleteMethod="#{bean.autocomplete}" var="item" fetchValue="#{item[0]}"
                                    value="#{bean.value}">
                                    <h:outputText value="#{item[0]}" styleClass="label"/>       
                                    <h:inputText id="autocompleteInputId" value="#{item[1]}" styleClass="hidden" readonly="true"/>
                                    <a4j:ajax listener="#{dataModel.actionEvent}" event="selectitem" execute="@this" render="render"/>
                                </rich:autocomplete>  

                                 

                                item[0] contains the name, and item[1] the id. In valueChange method you could get the id by searching in the requestParametersMap with the complete id of the inputText that contains the id:

                                FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("completeId:autocompleteInputId")

                                 

                                Anyway, be careful with the names, because if there are several items with the same name and differents id's, you will get the first id in the autocomplete.

                                 

                                Regards,

                                Rubén.

                                • 13. Re: Can I use rich:autocomplete for setting complex value?
                                  rizwanali89

                                  Hi....

                                   

                                  After i implement your solution when i go through the RequestParameterMap() did't show me the value of autocompleteInputId. instead its gives me the id the map show @Component. let me give you XHTM and map data.

                                  my XHTM for autocomplete is :

                                  <a4j:jsFunction name="autoCompleteCountryJSFunction"  render="selectedTransporter" execute="autocompleteCountryInputBox" action="#{referenceBean.selectAutoCompleteTransporter}" />

                                                                                                                            <rich:autocomplete id="autocompleteTransporterInputBox" minChars="1" autofill="false"  mode="cachedAjax" 

                                                                                                                               autocompleteMethod="#{referenceBean.autoCompleteSearchedTransporter}" var="transporter" fetchValue="#{transporter.name}" valueChangeListener="#{referenceController.myCheck}" converter="TranporterConverter">

                                                                                                                               <h:outputText value="#{transporter.name}" />

                                                                                                                                <h:inputText id="autocompleteInputId" value="#{transporter.id}" styleClass="hidden" readonly="true"/>

                                                                                                                                <a4j:ajax listener="#{referenceBean.selectAutoCompleteTransporter}" event="selectitem"/>

                                                                                                                             </rich:autocomplete>

                                   

                                  This is my requestparametermap.

                                  (java.util.Collections$UnmodifiableMap<K,V>) {queueId=undefined, mainform:linkTransporterName=Pakistan Air Line, javax.faces.source=mainform:autocompleteTransporterInputBoxInput, mainform:autocompleteTransporterInputBoxValue=AIRTRAN AIRWAYS, javax.faces.partial.ajax=true, mainform=mainform, mainform:autocompleteTransporterInputBoxInput=AIRTRAN AIRWAYS, javax.faces.partial.render=@component, javax.faces.partial.execute=mainform:autocompleteTransporterInputBoxInput @component, javax.faces.behavior.event=selectitem, org.richfaces.ajax.component=mainform:autocompleteTransporterInputBox, javax.faces.partial.event=selectitem, javax.faces.ViewState=1445088069264717809:-1027130532534318271}

                                   

                                  I think it autocompleteInputId repeat and requestparametermap is unable to find out which one is selected..

                                  any other solution.. I also use converter but the same problem.

                                  • 14. Re: Can I use rich:autocomplete for setting complex value?
                                    rizwanali89

                                    Hi ilya Shailkovsky,

                                     

                                    It will be so nice of you if you will give me a little help related to richface autocomplete component. I have almost try every possibilities and solution given on different forum but unable to pass the ID of an abject to the server side bean. For the time being I have implement this solution https://community.jboss.org/thread/165447 by Daniel Cárdenas it works perfectly but when i use the same thing on the other pages it's not working as perfect as the first one.

                                     

                                    For other pages i have implement https://community.jboss.org/thread/199113 by Andrea Martino its good. But it looks a little silly therefor I have to write my own custom component for this purpose can you give me little clue or code of some of your own custom component or a web reference URL from where i can write my own rich:autocomplete component.

                                     

                                    Another thing is why all the action related to the list are not working like clickonlist, onlistkeypress etc.

                                     

                                    Thanks in advance.

                                    1 2 Previous Next