0 Replies Latest reply on Jul 10, 2008 8:44 AM by Nicola Ben

    Suggestionbox: fetch an object

    Nicola Ben Novice

      Hi,
      I need to bind to an inputText an object.
      I retrieve with suggetionBox a city, and I need to persist the primary key of it.
      That's the code for suggestionBox:

      <h:inputText value="#{laboratoryHome.instance.city}" id="cityId" />
       <rich:suggestionbox id="citySuggestionBoxId"
       for="cityId"
       tokens=","
       rules="#{citySuggestionBox.rules}"
       suggestionAction="#{citySuggestionBox.autocomplete}" var="city"
       fetchValue="#{city}" first="#{citySuggestionBox.intFirst}"
       minChars="2"
      usingSuggestObjects="#{citySuggestionBox.usingSuggestObjects}">


      public List autocomplete(Object suggest) {
       String pref = (String)suggest;
       ArrayList<City> result = new ArrayList<City>();
      
       Iterator<City> iterator = getAllData().iterator();
       while (iterator.hasNext()) {
       City elem = iterator.next();
       if ((elem != null && elem.getName().toLowerCase().indexOf(pref.toLowerCase()) == 0) || "".equals(pref)) {
       result.add(elem);
       }
       }
       return result;
       }


      When I choose my city into inputText I get my city.toString() value.
      Any suggestion, please?

      Someone bind a suggestionBox value to a entity id?

      Thank you,
      N