Class AbstractAutoCompleteRenderer<T>

    • Method Detail

      • renderChoice

        protected abstract void renderChoice​(T object,
                                             Response response,
                                             String criteria)
        Render the visual portion of the assist. Usually the html representing the assist choice object is written out to the response use Response.write(CharSequence)
        Parameters:
        object - current assist choice
        response -
        criteria -
      • getTextValue

        protected abstract String getTextValue​(T object)
        Retrieves the text value that will be set on the textbox if this assist is selected
        Parameters:
        object - assist choice object
        Returns:
        the text value that will be set on the textbox if this assist is selected
      • getOnSelectJavaScriptExpression

        protected CharSequence getOnSelectJavaScriptExpression​(T item)
        Allows the execution of a custom javascript expression when an item is selected in the autocompleter popup (either by clicking on it or hitting enter on the current selection).

        The javascript to execute must be a javascript expression that will be processed using javascript's eval(). The function should return the textvalue to copy it into the corresponding form input field (the default behavior). the current text value will be in variable 'input'. If the function returns null the chosen text value will be ignored.

        example 1:

         protected CharSequence getOnSelectJavaScript(Address address)
         {
                final StringBuilder js = new StringBuilder();
                js.append("Wicket.DOM.get('street').value ='" + address.getStreet() + "';");
                js.append("Wicket.DOM.get('zipcode').value ='" + address.getZipCode() + "';");
                js.append("Wicket.DOM.get('city').value ='" + address.getCity() + "';");
                js.append("arguments[0]"); // <-- do not use return statement here!
                return js.toString();
         }
         
        example 2:
         protected CharSequence getOnSelectJavaScript(Currency currency)
         {
                final StringBuilder js = new StringBuilder();
                js.append("val rate = ajaxGetExchangeRateForCurrency(currencySymbol);");
                js.append("if(rate == null) alert('exchange rate service currently not available');");
                js.append("rate");
                return js.toString();
         }
         
        Then the autocompleter popup will be closed.
        Parameters:
        item - the autocomplete item to get a custom javascript expression for
        Returns:
        javascript to execute on selection or null if default behavior is intented