1 2 Previous Next 16 Replies Latest reply on Nov 30, 2010 11:31 AM by jaacen

    <rich:suggestionbox problem

    Eugene Bessel Newbie

      Hello everyone,

       

      I have a question about suggestionBox.

       

      this component contains an attribute suggestionAction, which transport the search word to backingBean. I didnt find an attribute which transport the ID from inputfield for which the suggestionBox is related.

       

      I generate more then one inputBoxes with suggestionBox, so I have always the same method for suggestionAction.

      when the user click into inputText and tip some letters then the method from suggestionAction is called.

      on this place I know which SuggestionBox is used.

       

      Do I have the possibility to know for which inputField the suggestionBox is activated?????

       

       

      thank you for your answer.

       

      wbr

      Eugene

        • 1. Re: <rich:suggestionbox problem
          Harut Sargsyan Apprentice

          Hi Eugene,

           

          You can place a4:support inside inputTexts and place a4j:actionparam into a4j:support... something like this:

           

          <h:inputText value="AAAAAAA"
                         id="INPUT_ID">

                         
                 <a4j:support event="onkeyup">
                              <a4j:actionparam name="inputIdForSugBox" value="INPUT_ID"
                                                        assignTo="#{myBean.inputId}"/>
                 </a4j:support>

                         
          </h:inputText>

           

          Where assignTo="#{myBean.inputId}" -- inputId is a String property of your Bean class (private String inputId;).

          So now "inputId" will have id of the input in which some text has been entered for sugestion-box...

          • 2. Re: <rich:suggestionbox problem
            Eugene Bessel Newbie

            hello Harut,

             

            that was my first idea too. but it didnt work. I think that the action for suggestionBox is called before a4j:support event is called. The attribute I setted in actionparam was null in my BBean.

             

            <h:inputText value="#{capitalsBean.capital}" id="text" />
                             <rich:suggestionbox id="suggestionBoxId"

                              suggestionAction="#{myBean.autocomplete}" var="result">

                                     <a4j:support event="onkeyup">
                                           <a4j:actionparam name="inputIdForSugBox" value="INPUT_ID"
                                                          assignTo="#{myBean.inputId}"/>
                                    </a4j:support>

                                     <h:outputText value="Border" />

                               </rich:suggestionbox>

            </h:inputText>

             

            perhaps I did something wrong??

            • 3. Re: <rich:suggestionbox problem
              Ilya Shaikovsky Master

              looks not really optimal. his request for suggestions also pointed to onkyup. So it will sees just stops working or will send two concurrent requests.

              • 4. Re: <rich:suggestionbox problem
                Ilya Shaikovsky Master

                remove support and use parameter simply nested to suggestionBox.

                • 5. Re: <rich:suggestionbox problem
                  Ilya Shaikovsky Master

                  simple test which works for me:

                   

                  <h:panelGrid columns="2" columnClasses="sb_test_column1,sb_test_column2" width="100%">
                  <h:inputText value="#{capitalsBean.capital}" id="text" />
                  <rich:suggestionbox id="suggestionBoxId" for="text" tokens=",[]"
                  suggestionAction="#{capitalsBean.autocomplete}" var="result"
                  fetchValue="#{result.name}" rows="#{suggestionBox.intRows}" reRender="out">
                  <f:param name="sbid" value="sbid"/>
                  <h:column>
                  <h:graphicImage value="#{result.stateFlag}" />
                  </h:column>
                  <h:column>
                  <h:outputText value="#{result.name}" />
                  </h:column>
                  <h:column>
                  <h:outputText value="#{result.state}" style="font-style:italic" />
                  </h:column>
                  </rich:suggestionbox>
                  <h:outputText id="out" value="#{userBean.name}"/>
                  </h:panelGrid>
                  

                   

                  and

                   

                       public List<Capital> autocomplete(Object suggest) {
                          System.out.println(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("sbid"));
                  

                  • 6. Re: <rich:suggestionbox problem
                    Eugene Bessel Newbie

                    hello Ilja,

                     

                    thank you for your advice. I will test this solution.

                     

                    thank you.

                     

                    wbr

                    Eugene

                    • 7. Re: <rich:suggestionbox problem
                      Eugene Bessel Newbie

                      hello Ilja,

                       

                      I would like to use suggestionBox for InputField, which should use as Filter.

                       

                      So when I chose some value from suggestionBox, some actionBean Method should be called.

                       

                      Can I use a4j:support event="onblur" with suggestionBox?

                       

                      suggestionBox has a parameters:

                      usingSuggestObjects="true"
                      onobjectchange="processObjectsChange(suggestion)">

                       

                      but on this place the JavaScript function is called.

                      which parameter should I use for calling of the method from Bean??

                      • 8. Re: <rich:suggestionbox problem
                        Ilya Shaikovsky Master

                        point a4j:support to onselect.

                        • 9. Re: <rich:suggestionbox problem
                          Eugene Bessel Newbie

                          hello Ilja,

                           

                          in your code


                          you iterate throw two columns. You have two inputFields and two SuggestionBoxes.

                          but each suggestionBox has
                          <f:param name="sbid" value="sbid"/>
                          it is always the same, or not?

                          how do you know in bbean whether the user clicked inputtext1 or inputtext2???

                          should the value of
                          FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("sbid")
                          be always sbid ???


                          • 10. Re: <rich:suggestionbox problem
                            Eugene Bessel Newbie

                            hello Ilja,

                             

                            you are right the parameter of sbid is the column name.

                             

                            when I enter some letter into inputField, the method autocomplete is called. On the end of the method is the result also not empty, BUT the suggestionBox is not opend.

                             

                            Do you have some idea why?

                            did I implement something wrong?

                             

                            my code:

                            <rich:columns value="#{myDataTable.columns}" var="columns"
                                            index="ind" id="filterTable">
                                            <h:panelGrid columns="1">
                                                <h:outputText value="#{columns}"></h:outputText>

                                                <h:inputText id="TextFilter_#{columns}" value="#{myDataTable.columnFilterValues[columns]}">
                                                <rich:suggestionbox id="suggestionBoxForTextId_#{columns}" for="TextFilter_#{columns}"

                                                     suggestionAction="#{myDataTable.autocomplete}" var="result">
                                                <f:param name="sbid" value="#{columns}"/>
                                                <h:outputText value="#{result}"/>
                                                </rich:suggestionbox>
                                                </h:inputText>

                             

                             

                            public Set<String> autocomplete(Object suggest) {

                                       String column = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("sbid");
                                       int index = 0;
                                       for(int i = 0;i<getColumns().size();i++){
                                           if(getColumns().get(i).equals(column)){
                                            index = i;
                                            break;
                                           }
                                       }
                                       String pref = (String) suggest;

                             

                                       Set<String> result = new HashSet<String>();

                                       Iterator<DataRow> iterator = resultList.iterator();

                             

                                       while (iterator.hasNext()) {

                             

                                       DataRow elem = (iterator.next());

                             

                                       if ((elem.getRowData().get(index) != null
                                               && elem.getRowData().get(index).toLowerCase().indexOf(pref.toLowerCase()) == 0)
                                               || "".equals(pref)) {         
                                           result.add(elem.getRowData().get(index));         

                                       }

                             

                                 }

                            return result;

                            }

                            • 11. Re: <rich:suggestionbox problem
                              Eugene Bessel Newbie

                              I have implemeted only one field with suggestionBox and <f:param

                              and it works.

                               

                              can it be possible that suggestionBox has a problem with my dynamic generation??

                              • 12. Re: <rich:suggestionbox problem
                                Eugene Bessel Newbie

                                I have heard that the component suggestionBox have a problem if I set it into one table.

                                 

                                does anybody know this problem?

                                 

                                I tried to implement it with dataGrid and Table and got the same behavior. The action Method is called, but the sugestionBox was not opened.

                                • 13. Re: <rich:suggestionbox problem
                                  Ilya Shaikovsky Master

                                  no in general there should be no problems with suggestion usage in tables., I made some tests in the past and it worked fine for me.

                                  • 14. Re: <rich:suggestionbox problem
                                    jaacen Newbie

                                    I am having that problem.  I have a rich:suggestBox that works perfectly until i put it inside a h:dataTable at which point I notice this in a4j:log:

                                    ...

                                    debug[15:45:12,189]: call getElementById for id= edit-form:phNumbers:suggestionBoxIDa:suggest
                                    warn[15:45:12,189]: Node for replace by response with id edit-form:phNumbers:suggestionBoxIDa:suggest not found in document
                                    ...
                                    by doing a view source in the browser it looks to me like it should be calling getElementById for id edit-form:phNumbers:0:suggestionBoxIDa:suggest  (where 0 is the dataTable row index)
                                    here's my code:
                                                                  <h:dataTable rows="3" value="#{myBean.fruits}" var="testTable" >
                                                                              <h:column id="colA" >
                                                                                  <h:inputText id="s" value="#{myBean.s}" />
                                                                                <rich:suggestionbox id="suggestionBoxIDa" var="v" for="s" ajaxSingle="false" selfRendered="true"  suggestionAction="#{myBean.picker.autocomplete}">
                                                                                 <h:column>
                                                                                   <h:outputText value="#{v.label}" />
                                                                                 </h:column>
                                                                                </rich:suggestionbox>
                                                                            </h:column>
                                                                            <h:column >
                                                                                <h:outputText value="#{testTable}"/>
                                                                            </h:column>
                                                                        </h:dataTable>
                                    note that myBean.picker.autocomplete IS firing (I checked this with a logger) but the suggestionbox is NOT rendering in the page.  (once again, works FINE if I remove the dataTable)
                                    1 2 Previous Next