2 Replies Latest reply on Aug 6, 2007 4:43 AM by Simon

    Get selected Row When the user completes a selection in sugg

    Madhav Bhargava Newbie

      Hi All,

      There are a couple of suggestionBox components that together form a search form. All of these suggestionbox components are populated from the database. Now the bean that populates all the components contains an ID field using which the final search query will be created.

      The problem is that when the user starts typing something and decides to autocomplete it by selecting a value from the list of options available in the popup that comes up then the text value is populated in the inputText component but there is no way i can get the ID of the selected row.

      I thought of a few ways of doing it:

      1. If i can specify more than one inputText component to populate and then in one populate the text value that is selected and make the other input component as hidden which will then get the ID. I can see that i can specify more than one inputText component using the for property but then i can only specify one value in the fetchValue property. Unless i am overseeing something this option gets ruled out.

      2. I tried to embed a4j:support component like the one below:

      <h:inputText value="#{suggestionBox.property}" id="text" />
      <rich:suggestionbox id="suggestionBoxId" for="text" tokens=""
       suggestionAction="#{suggestionBox.autocomplete}" var="result"
       fetchValue="#{result.text}" rows="#{suggestionBox.intRows}"
       border="#{suggestionBox.border}" width="#{suggestionBox.width}"
       <h:outputText value="#{result.text}" />
       <a4j:support event="onselect" actionListener="#{suggestionBox.onSelectListener}"/>

      ActionListener gets called when the user selects and autocompletes. Now when i try to call getRowData() then it throws an IllegalStateException. I think that at this point there is no row data and therefore this exception. I am not able to figure out how to use a4j components to get either the selected row bean from which i can extract the ID or the ID directly, so this option is temporarily ruled out.

      3. I read through the resolutions to similar (not exactly similar) issue but then could not make out much how those can be used to get the selected row bean as we do in normal data table which is also UIData component.

      I am running out of options. Can anyone think of a way in which i can achieve it.