1 Reply Latest reply on Mar 9, 2010 9:11 AM by Ilya Shaikovsky

    Suggestionbox is sluggish

    Tanya Ruttenberg Expert

      I make liberal use of suggestionboxes in my app.   For example:

       

      <h:inputText id="it30" value="#{devices.name}"
            onkeypress="#{rich:component('s30')}.callSuggestion(true)" />
          <rich:suggestionbox id="s30"
            suggestionAction="#{deviceNameList.suggest}" var="_dev" for="it30"
            nothingLabel="Device not found">
            <h:column>
              <h:outputText value="#{_dev}" id="ot3" />
            </h:column>
          </rich:suggestionbox>

       

      Here is the code backing up the suggestionAction:

       

      public class DeviceNameList extends EntityQuery<String> {
         
          List<String> devList = new ArrayList<String>();
         
          @Override
          public String getEjbql() {
              // TODO Auto-generated method stub
              return "select d.name from Devices d order by d.name";
          }

          public DeviceNameList() {
              this.devList = getEntityManager().createQuery(this.getEjbql()).getResultList();
          }

          public List<String> suggest(Object input

         

              if (input==null) {

                             return returnDevices;

                      }

                     String searchString = (String) input;

              List<String> returnDevices = new ArrayList<String>();

              Iterator<String> iterator = devList.iterator();

              while (iterator.hasNext()) {
                  String element = (String) iterator.next();
                  if (element.toLowerCase().contains(searchString.toLowerCase())) {
                      returnDevices.add(element);
                  }
              }
              return returnDevices;
          }
         

      }

       

      But I find the response time to be quite sluggish, though not all the time.  In this case my potential list of suggestions has over 6,000 elements in it.  Is this simply too much?  I feel the same sluggishness with a suggestion list of only 50 hard-coded state names (AK, AL, etc).  I'm ready to release this to beta-testers,but I still feel the suggestionbox is performing as it should.

       

      Any suggestions?

       

      TDR

        • 1. Re: Suggestionbox is sluggish
          Ilya Shaikovsky Master

          At first I think nobody will scroll the list which contains 6000 elements to find proper one. I would rather expect that the user will enter some more caracters. So maybe some solution like

           

          • Option1
          • ...
          • option 100
          • First 100 Options shown

           

          will suit your needs?

           

          And the second - which scope your bean has? If request - db call will occurs on every request. And it also not looks like optimal solution.

           

           

          In general all the SB component functionality is to call your suggestion method and ask for some list of suggestions. So almost all the performance tuning should be adressed to your object.