3 Replies Latest reply on Apr 7, 2015 1:07 PM by Jonathan Laterreur

    autocompleteMethod example

    Mohamed Benameur Newbie

      Hellow everybody.

      I'm trying to set up rich:select similar to the third one in the showcase.

      it's my first time.

      the problem is that i didn't find a full example that explain the autocompleteMethod (how to encode the java bean method)

      so if some one can help i'll be thankful.

        • 1. Re: autocompleteMethod example
          Jonathan Laterreur Newbie

          Example for a autocomplete component :

           

          <rich:autocomplete id="auto" autocompleteMethod="#{autoCompleteBean.searchAutoComplete}"

            value="#{autoCompleteBean.value}" minChars="2">

            <a4j:ajax event="selectitem" execute="@this" render="@this"

            listener="#{autoCompleteBean.selectItemListener}" />

          </rich:autocomplete>

           

          @ManagedBean

          @ViewScoped

          public class AutoCompleteBean implements java.io.Serializable {

            private static final long serialVersionUID = -8232534836884753440L;

           

            private String value;

           

            public String getValue() {

            return value;

            }

           

            public void setValue(String value) {

            this.value = value;

            }

           

            /**

            * Select item autocomplete.

            *

            * @param event

            */

            public void selectItemListener(AjaxBehaviorEvent event) {

            System.out.println("select item listener");

            }

           

            /**

            * Autocomplete.

            *

            * @param search

            * @return

            */

            public List<String> searchAutoComplete(String search) {

            List<String> lst;

            System.out.println("search auto complete");

            lst = new ArrayList<String>();

            for (int i = 0; i < 10; i++) {

            lst.add("auto " + i);

            }

            return lst;

            }

          }

          • 2. Re: autocompleteMethod example
            Michal Petrov Master

            Shouldn't you maybe use the parameter for something?

            • 3. Re: autocompleteMethod example
              Jonathan Laterreur Newbie

              What do you mean? String search? Indeed, I could. Like lst.add("auto " + i); to lst.add(search + i);