6 Replies Latest reply on Apr 19, 2007 7:47 AM by sijk

    suggestionbox  and onselect

    liuliu

      hi,

      i want to rebuild some list in my backingbean when user select a value in the suggestion list. i use a4j:support for onselect event, but then i finded that i cant get the value selected in this method.

      any suggestion?

      thanks in advance

      liu

        • 1. Re: suggestionbox  and onselect
          damianharvey

          You shouldn't need to use a4j:support. Are you using the rich:suggestionBox? If so you create a bean action called by the suggestionAction eg:

          <rich:suggestionBox suggestionAction="#{searchScheduleHelper.suggest}" ...etc


          An example of using a Database to populate the suggestionAction looks like this:
          public List suggest(Object in) {
           String pref = in.toString().toLowerCase() + "%";
           Query q = entityManager.createQuery("select u from UnLocode u where lower(u.nameWoDiacritics) like :pref")
           .setParameter("pref", pref)
           .setMaxResults(10);
          
           ArrayList results = (ArrayList)q.getResultList();
          
           return results;
          }
          


          • 2. Re: suggestionbox  and onselect
            liuliu

            hello,

            thanks to your reply. i think i have not explain my problem clearly.

            what i search is when the user select a value in the list, i should rebuild some other list. suggestionAction is make for when we are typing in the text box. my problem is i have no way to know which line is selected by user.

            • 3. Re: suggestionbox  and onselect
              ilya_shaikovsky


              <h:inputText value="#{bean.property}" id="test"/>
               <rich:suggestionbox for="test" width="200" height="200" suggestionAction="#{bean.autocomplete}" var="cap">
               <a4j:support event="onselect" reRender="output"/>
               <h:column>
               <h:outputText value="#{cap.text}"/>
               </h:column>
               </rich:suggestionbox>
              

              As far as you have the input and suggestion in one region bean.property will be submitted on ajax request from support. So you may use bean.getProperty to get this value.


              • 4. Re: suggestionbox  and onselect
                liuliu


                yes, you are right. i have bean.property,but sometimes we want the id not the description. i noticed the component htmlsuggestionbox has getrowdata, why not pass the rowdata to method onselect?

                l

                • 5. Re: suggestionbox  and onselect
                  ilya_shaikovsky

                  But having one of the objects property you may get another for this object i think..

                  • 6. Re: suggestionbox  and onselect
                    sijk

                     

                    "liuliu" wrote:

                    yes, you are right. i have bean.property,but sometimes we want the id not the description. i noticed the component htmlsuggestionbox has getrowdata, why not pass the rowdata to method onselect?


                    Have you found a solution for this problem?

                    I would also like to pass the selected id to the bean so other information on the page could be updated.