1 Reply Latest reply on Aug 12, 2011 8:36 PM by vace117

    RF4 <rich:autocomplete> - How to make the button send the ajax request?

    vace117

      I can't seem to find an option for making the drop down button on <rich:autocomplete>  in RF4 to send an ajax request. So, I have this code:

       

      {code}

      <rich:autocomplete mode="ajax" showButton="true" autofill="false"

         id="suggestionForMeasurementValue"

         value="#{registeredBackingBean.selectedTargetMeasurementDetailLabel}"

         autocompleteMethod="#{registeredBackingBean.suggestTargetMeasurementDetails}"

         minChars="0" />

      {code}

       

      When I click the drop down button with empty input field, I'd like it to send a request to selectedTargetMeasurementDetailLabel method and populate the drop down. Instead it just shows me an empty drop down.

       

       

      Can someone tell me how to do this?

        • 1. Re: RF4 <rich:autocomplete> - How to make the button send the ajax request?
          vace117

          It looks like the reason this doesn't work is b/c AutocompleteRenderer.getMinCharsOrDefault() forces minChars to 1, if it's less than one.  This effectively prevents us from being able to see the whole, unfiltered list by pressing the drop-down button, which I think is a useless limitation. So, here is the fix:

           

           

          {code}

          /**

          * Allows rich:autocomplete to specify 'minChars="0"'. This is useful if you want to be able to

          * press the drop-down button ('showButton="true") and have the drop down display

          * the whole, unfiltered list.

          *

          * @author Val Blant

          */

          public class ZeroCharsFixAutocompleteRenderer extends AutocompleteRenderer {

           

           

                  @Override

                  protected int getMinCharsOrDefault(UIComponent component) {

                    int value = 0;

                    if (component instanceof AbstractAutocomplete) {

                        value = ((AbstractAutocomplete) component).getMinChars();

                        if (value < 0) {

                            value = 0;

                        }

                    }

           

                    return value;

                  }

          }

          {code}

           

          And in faces-config.xml:

           

          {code}

          <renderer>

              <component-family>javax.faces.Input</component-family>

              <renderer-type>org.richfaces.AutocompleteRenderer</renderer-type>

              <renderer-class>ca.gc.agr.agrishare.web.jsf.components.ZeroCharsFixAutocompleteRenderer</renderer-class>

          </renderer>

          {code}