6 Replies Latest reply on Apr 5, 2011 1:14 PM by Fred Fred

    rich:autocomplete: How to set two hiddenfield?

    Fred Fred Newbie

      Hi guys,

      i'm pretty new to Richfaces4.

       

      I'm trying to have the rich:autocomplete tag to work, and when the search is done, for example the search of a editors name, I want to set the ID of the editor selected in a hidden field, as in JQuery it's easy to do.

       

      My code is running fine, as my bean is returning a list of editor and when I select the name of an editor, I can update the autocomplete field. But it's not enought, because my action bean will need th editor ID, not the name. So when the autocomplete has done his job, I want to retreive the ID and set it to an hidden var.

       

      Currently my code is :

       

        <rich:autocomplete  autocompleteMethod="#{AuthorController.autocompleteSearchEditor}"

                                                                                                          showButton="false"

        mode="cachedAjax"

                                                                                                          attached="true"

                                                                                                          minChars="2"

                                                                                                          autoFill="true"

                                                                                                          layout="table"

        var="autocomplete_editor"

        value="#{AuthorController.currentEditBook.teditor.name}"

        fetchValue="#{autocomplete_editor.name}"

        >

       

      <rich:column>

        <h:graphicImage name="printer_empty.png" library="images"/>

        </rich:column>

        <rich:column>

        <h:outputText value="#{autocomplete_editor.name}"/>

        </rich:column>

       

        </rich:autocomplete>


      is anybody able to help me ?

       

      Thanks !!!

        • 1. rich:autocomplete: How to set two hiddenfield?
          Nick Belaevski Master

          Hi Fred,

           

          Have you checked rich:select component? It allows you to place selected object into model without any additional application code required.

          • 2. rich:autocomplete: How to set two hiddenfield?
            Fred Fred Newbie

            Hi Nick,

            thanks a lot for your reply.

             

            This is a good "workaround" i can use, but it's true that I wanted to try a code like 'a4j:ajax' with the 'oncomplete' event to get the ID retreive and to "store" it in a bean property. If this is not possible, I'll certainly use rich:select.

             

            This may be consuming (in memory) if my rich:select is hosting 10000 entries.

             

            What do you think about it ?

             

             

            Originaly, I wanted to use autocomplete AJAX because of the "asynchronous" / 'lite' memory consuming.

             

            Thanks again for your reply,

            Fred

            • 3. rich:autocomplete: How to set two hiddenfield?
              Rocky S Master

              just trying to understand your problem, you are trying to retrieve the id property of autocompleteSearchEditor. if yes can you post its code.

              • 4. Re: rich:autocomplete: How to set two hiddenfield?
                Fred Fred Newbie

                Hi,

                Sorry if i'm not clear.

                What i Want to do is simple : searching an editor by it s name, but When selected, store its name in a input text and its ID In an other field.

                 

                The autocompleteSearchEditor just return a list of object 'teditor' that is a POJO annoted @entity describing the teditor data in the database.

                So when returned, I am able to find the ID from the object returned.

                 

                To traduce this in code:

                 

                In a form, i have some input fields. One of them is an input tex t and the other is an hidden field.

                When searching entering first char of an editor, i ve got a list of selected editors. I can select my editor's name. All is cool.

                What is missing, as a functionnality for me, is to be able to store the ID of the editor in a other variable, and when a send my form for processing I can get the editor object from database by its ID.

                 

                Am I more clear now ?

                 

                 

                Thanks

                Fred

                 

                PS: here is the code (since I was not on my MAC the first time I wrote my answer)

                 

                /**

                                     * autocompleteEditor

                                     * @param pattern

                                     * @return

                                     */

                                    public List<Teditor> autocompleteSearchEditor(String pattern)

                                    {

                                              try {

                                                        List<Teditor> list = editorEJB.listEditors(pattern);

                                                        if (list==null)

                                                                  return new ArrayList<Teditor>();

                                                        else

                                                                  return list;

                                              } catch (Exception e) {

                                                        return new ArrayList<Teditor>();

                                              }

                                    }

                • 5. rich:autocomplete: How to set two hiddenfield?
                  Rocky S Master

                  cool I understood this thing. I assume when you say ID it is an property of object/entity teditor.

                   

                  Already you are using this to get the name of selected editor-

                   

                  <h:outputText value="#{autocomplete_editor.name}"/>

                   


                  Why not output the ID value also?

                   

                   

                  <h:outputText value="#{autocomplete_editor.ID}"/>

                   

                  And you can make it hidden also if you want.

                  • 6. rich:autocomplete: How to set two hiddenfield?
                    Fred Fred Newbie

                    because <h:outputText value="#{autocomplete_editor.name}"/> has only a means between the "rich:column" definition.

                     

                    however, i'll try your idea. If it works, i'll feedback the full solution.