5 Replies Latest reply on May 16, 2011 10:32 AM by rread

    Help With Autocomplete

    rread

      I am having a hard time with autocomplete,

       

      i need to build a autocomplete that searches by its description and once a option is selected it redirects to a page

      with the id tied to the description.

       

      i got the Following

       

       

       

      public interface IEntTest {

           public String getId();

           public String getDescription();

      }

       

      @ManagedBean

      public class SearchBean {

           private IEntTest value;

       

           public List<IEntTest> search(final String prefix) {

       

                final List<IEntTest> result = <CALL TO SEARCH SERVICE>

                return result;

           }

      }

       

       

      <rich:autocomplete id="descSearch" minChars="2" value="#{searchBean.value}" autocompleteMethod="#{searchBean.search}" >

      </rich:autocomplete>

       

       

      i have tried many aproaches but i cannot seem to be able to make it work,

      can any one help me here?

       

      in short it needs

      1. Search

      2. Seleact a option present at the autocomplete.

      3. Once the option is selected do a submit to a second page with the id as parameter.

       

      Any help will be apreciated

        • 1. Help With Autocomplete
          mp911de

          Hi Felix,

          take a look at http://community.jboss.org/wiki/richfacesautocompletecomponentbehavior.

           

          You should use Column-Definitions for your Auto-Complete as described in the article. Additionally, I think the Suggestion-Signature should be:

           

          public List<IEntTest> search(Object input)

          {

               String prefix = (String) input;

               ...

          }

           

          Best regards,

          Mark

          • 2. Re: Help With Autocomplete
            rread

            that part i know, but what i am interested in is that when i select a option it automatically redirects me to another page, sending either the id or a instances of IEntTest

             

            i have this but it does not fill my needs

             

            <rich:autocomplete id="descPrueba" minChars="2" value="#{searchBean.id}" autocompleteMethod="#{searchBean.search}" var="result">

                    <h:inputHidden value="#{result.id}" id="ID" visible="false"/>

                    <h:outputText value="#{result.descripcion}"/>

                    <h:commandLink value="#{result.descripcion}" action="/test/edit.xhtml" />

            </rich:autocomplete>

             

            i would like it do be on the selection of the element instead on the commandlink action

            • 3. Re: Help With Autocomplete
              rread

              In the end i come up with this but there is still something wrong cause the testEditBean does not resieve the data send by the command link

               

               

              <rich:autocomplete id="descTest" minChars="2" autocompleteMethod="#{searchBean.search}" var="result">

                 <h:commandLink value="#{result.desc}" action="/test/edit.xhtml" >

                   <f:setPropertyActionListener value="#{result}" target="#{testEditBean.data}"/>

                </h:commandLink>

              </rich:autocomplete>

               

               

              public class TestData implements Serializable {

                   String id;

                   String desc;

                   String value;

                  

                   <getter and setters acording to Java Bean Standard>

               

                   public boolean commit(){

                        <Commits the data of test>

                   }

              }

               

               

              @ManagedBean

              @RequestScoped

              public class TestEditBean implements Serializable {

                   private TestData data;

                  

                   <getter and setter for data>

               

                   public boolean commit(){

                        data.commit();

                   }

              }

              • 4. Re: Help With Autocomplete
                ilya_shaikovsky

                you should realize that autocomplete is Input component and the only way you could convert submitted String to some object by using JSF converters.

                 

                and if need built-in selection of value-label type consider rich:select usage.

                • 5. Re: Help With Autocomplete
                  rread

                  My Requirements are these,

                  i have a autocompletes who keeps seaching in a database by a description, wich the user is putting in.

                  once he select the one he wants from what the autocompletes brings, it must automatically redirect him

                  to another page with either the object selected or the id of the object selected, wich must be stored in a bean for the second page to use.

                   

                   

                  Example :

                   

                  User A wants enters the first page called search.xhtml

                   

                  he has a autocomplete who seachers for a item by a description, he starts to fill in the discription,

                  as he writes the description the autocompletes, show him a list of possible object that fit that description.

                  Onces he sees the one he wants in the list, he select it, and he is the redirected automatically to

                  the edit.xhtml page, wich uses a editBean which was filled withe the object selected.