3 Replies Latest reply on Feb 3, 2014 4:13 PM by bleathem

    rich:autocomplete issues

    atulajoshi24

      We are upgrading from jsf 1.2 to jsf 2.

      We are using apache myfaces 2.1 and rich faces 4.3.

       

      We are facing very strange issue with  <rich:autocomplete>. Below is the xhtml code.

       

       

            <rich:autocomplete mode="cachedAjax" minChars="2" autocompleteMethod="#{bean.getData}"
                              var="result" value="#{bean.inputData}">
                                          <h:column>
                                          <h:outputText value="#{result}" />
                                      </h:column>
            </rich:autocomple
      te>
      The above autoComplete component gets included through ui include tag as below
      <ui:include src="panel1.xhtml">
          <ui:param name="bean" value="#{userBean}"/>
      </ui:include>
      

       

      Following is the scenario , when an input is entered in an autocomplete input box , suggetions are shown - that is bean.getData method is called.

      Surprisingly , after any of the suggestion is selected , bean.getData method is called again with chosen option value , which I believe is not the correct behaviour

      since user has selected an option and not typed any input.

       

      I don't want the bean.getData method to be called again. Is there any alternative ?

      In addition to above issue , it seems that there is no "nothing label" attribute for rich:autocomplete which was present for rich:suggestionBox which comes into picture when there is no result found.

      This issue alongwith above issue is really making a difficult job to get this component working same as rich:suggestionBox

       

      I understand that once prefix for search is changed , suggestions are evaluated again ,but here i am not changing the prefix but selecting the entire suggestion value.

      Following is the detailed code for the issue

       

      When autoCompleted method is called , it populates a hashMap with all the suggestions with CustomUserObject as the value.

      Below is the code for this :

       

      public List<String> getData(FacesContext context, UIComponent component, String input) {
      
              Map<String, CustomUserObject> userMap = new HashMap<String, CustomUserObject>();
              //get users from db
             List<CustomUserObject> users = bean.fetchUserList(input);
      
          //put users in map
              for (CustomUserObject user : users) {
                  userMap.put(user.id, user) ;
              }
      
              List<String> userList = new ArrayList<String>();
      
              //convert the list to List<String>
              if(userList != null && !userList.isEmpty()){
      
                  //convert the List<CustomUserObject> to List<String>
              }
              return userList;
      
      
      
      
      

          }

       

      Now because of the issue mentioned in the question , getData is called again and corrupts userMap.

      This map is used to retrieve correct CustomUserObject by comparing it with selected Suggestion like below :

       

        if(userMap != null && !userMap.isEmpty()){
                      for(CustomUserObject user : userMap.values()){
                   
                   
                          if(selectedSuggestion != null && selectedSuggestion.equals(user.name)){
                              //match is found
                          //set variables to update ui at re-render
      
                          }
                          //no match found
                      //set variables to update ui at re-render
            
                      }
                  }
      
      
      
      
      
        • 1. Re: rich:autocomplete issues
          bleathem

          Does it works as expected with Mojarra?

          • 2. Re: rich:autocomplete issues
            atulajoshi24

            Thanks Brian for your repply.

            I haven't tried with Mojarra yet since my application already uses my faces and we really cannot change that.

            What I am thinking is , is therer any way i can send some special value to autocompleteMethod when any suggestion is selected , so that we can differentiate that it is

            the item selected event ?

            • 3. Re: rich:autocomplete issues
              bleathem

              Trying (a simple reproducer) with Mojarra would be useful to determine the origin of the extraneous autcomplete data call.  If you can share such a simple reproducer (or if you can provide instructions to reproduce with the showcase) than we can dig into the problem.