12 Replies Latest reply on Jul 2, 2008 3:33 PM by Adam Buckley

    How do I link

    Yaron IM Newbie

      Hi,
      I'm using the suggestionbox control for a list of users that I want to send mail to. My problem is that I'm getting just the name of those users as a String comma separeted, but I can't get the users entities according those names (because I can have two or more users with the same name etc.)

      How can I link the result of the suggestion box to a List of entities?

      Thanks in advance,
      Yaron.

        • 1. Re: How do I link
          Ilya Shaikovsky Master

          We've implemented objects suggestion in this version. But unfortunatelly JS API for simplest management of this feature still isn't completed.
          http://jira.jboss.com/jira/browse/RF-413

          But your task could be done using next scenario.

          1) add usingSuggestObjects="true" to SB component
          2)use onobjectchanged event to store objects currently selected using sb component.
          3) objects stores under suggestion.SelectedItems array.
          4) each array element contains of text and object properties.
          5) so you should iterate this array get not null objects and get the property you need.

          If you check the developers sample to SB and add
          onobjectchange="console.log(suggestion.selectedItems[0].object.price)"
          to second suggestion component - you'll see the price property written in Firefox log every time when objects updated.

          • 2. Re: How do I link
            Ilya Shaikovsky Master

            about 2) just store your emails properties selected to some hidden for example.

            • 3. Re: How do I link
              Mark LoSacco Newbie

              I actually have a very similar need -

              Basically I want to allow user to begin typing in the last name of a mamber and then have the suggestion box show all matches. These members each correspond to a database member record.

              When user selects a name I wish to capture the id of the record corresponding to the name, but display the name in the editbox.

              I read the suggested work around but am not sure I understand. In my case I am using Seam and would like to initialize an EntityHome component based on the selection.

              Is this more trouble than its worth? Contemplating switching to an alternate method of selecting the record, even though using the SB would be ideal...

              • 4. Re: How do I link
                Julien Sere Newbie

                Hi everybody !
                I've find a little trick that allow you to retrieve the selected OBJECT from a suggestion box.

                You just need to add an setPropertyActionListener which gives you the opportunity to retrieve the bean you have selected in your suggestion list

                <rich:suggestionbox id="suggestionBoxId" for="text" width="450" height="150"
                suggestionAction="#{mybean.autocomplete}" var="car" fetchValue="#{car.label}">
                <h:column>
                 <h:outputText value="#{car.label}" />
                </h:column>
                <a4j:support event="onselect">
                 <f:setPropertyActionListener value="#{articlepf}" target="#{formController.selectedCar}" />
                </a4j:support>
                </rich:suggestionbox>
                


                This is a very simple way to bypass the current limitation of suggestion box.
                If you have any comment of it let me know.

                • 5. Re: How do I link
                  Ilya Shaikovsky Master

                  This workaroung already in our FAQ for a half of the year ;)

                  But unfortunatelly - it will not help if you will submit form externally.

                  In previous post I've just described how to store the objects property in order to get it submitted with external controls also.

                  And b.t.w. suggestionBox client side api already implemented. ;)

                  • 6. Re: How do I link
                    Simon Cigoj Newbie

                    Can someone post a complete tutorial inclouding the bean code that handles everything...I don't understand how the mentioned theqniqe by ilya_shaikovsky could be perormed.

                    For example i dont understand this :
                    2)use onobjectchanged event to store objects currently selected using sb component.

                    How can you use onobjectchanged event what is the code in the bean?

                    Or mybe JulienSere if could explain what is the articlepf in the value of setPropertyActionListener in his example...could you pleas post also the bean code?

                    I think it would be very helpful for many developers.

                    • 7. Re: How do I link
                      Julien Sere Newbie

                      Sorry for the error.
                      Just replace the line

                      <f:setPropertyActionListener value="#{articlepf}" target="#{formController.selectedCar}" />
                      by this one
                      <f:setPropertyActionListener value="#{car}" target="#{formController.selectedCar}" />


                      Now in your backing bean (in my case this is the formControler managed bean) you will have a propertie with setter and getter
                      private Car selectedCar;

                      This propertie will be update with the object you have selected in your suggestion box.
                      Note that this technique is not the one provide by ilya_shaikovsky
                      It's only another trick with some limitation but it's working for me

                      • 8. Re: How do I link
                        Simon Cigoj Newbie

                        Tnx for your help JulienSere, your theqnique it works also for me now.

                        I'm looking foreward for the beret object support in rich:comboBox...it looks a promising component...and I hope also for better obbject supporti in suggestionbox

                        • 9. Re: How do I link
                          Brendan Farragher Newbie

                          I also need to retrieve an entire entity bean (not just one attribute) when the user makes a selection from the suggestion. Unfortunately, in my case, I am restricted to using RichFaces 3.1.0.

                          I implemented what JulienSere had suggested with setPropertyActionListener:

                          
                          <f:setPropertyActionListener value="#{result}" target="#{bean.selectedEntry}" />
                          
                          


                          The selectedEntry method fires, but the method argument which contains the selected entry object is null :(. After searching around a little I found this jira,which describes exactly what is happening to my app.It says that this null argument problem is a bug with version 3.1.0:

                          http://jira.jboss.org/jira/browse/RF-923;jsessionid=691170C187DCB362DD9AB95D05F61693

                          Is there any way, *in version 3.1.0*, to receive the selected bean, *OR* multiple attributes, from the suggestion box result list and store it in an attribute(s) of the bean?

                          Thanks.

                          • 10. Re: How do I link
                            Brendan Farragher Newbie

                            Just for clarity, what ilya_shaikovsky had suggested will not work in my case because the useSuggestObjects attribute does not exist in 3.1.0.

                            Thanks.

                            • 11. Re: How do I link
                              Gerrit Brehmer Newbie

                              Hi,

                              i'm using RichFaces 3.2.1 and the code snippet from here/FAQ to save the selected object.
                              I have two input fields and both have an own suggestion box. both are connected to the same object but other members.
                              Now, if i select a suggestion in the first input field i want to rerender the second input field with new value from updated object. but after that, the suggestionbox on that rerendered input field doesn't function anymore.


                              • 12. Re: How do I link
                                Adam Buckley Newbie

                                I also had real problems passing an object back to a backing bean property, after selecting it using a suggestionbox. The only way I could get this to work was as follows:

                                <h:inputText id="productSearchBox" />
                                
                                <r:suggestionbox for="productSearchBox" suggestionAction="#{productSearch.suggestProducts}" var="productHit">
                                 <h:column>
                                 <h:outputText value="#{productHit.description}" />
                                 </h:column>
                                
                                 <a:support event="onselect" reRender="productDescription" action="#{productSearch.retrieveProduct}">
                                 <f:setPropertyActionListener value="#{productHit}" target="#{productSearch.chosenProduct}" />
                                 </a:support>
                                </r:suggestionbox>


                                Note that I could not bind the inputText to a backing bean property like this:
                                <h:inputText value="#{productSearch.chosenProduct}" id="productSearchBox" />


                                In this case a ConversionException was always thrown.

                                I still haven't figured out if this will actually fit my needs, but I hope to post again soon.