Class AbstractAutoCompleteRenderer<T>
- java.lang.Object
-
- org.apache.wicket.extensions.ajax.markup.html.autocomplete.AbstractAutoCompleteRenderer<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
Serializable
,IAutoCompleteRenderer<T>
,IDetachable
,IClusterable
- Direct Known Subclasses:
AbstractAutoCompleteTextRenderer
public abstract class AbstractAutoCompleteRenderer<T> extends Object implements IAutoCompleteRenderer<T>
A renderer that abstracts auto-assist specific details and allows subclasses to only render the visual part of the assist instead of having to also render the necessary auto-assist javascript hooks.- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractAutoCompleteRenderer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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).protected abstract String
getTextValue(T object)
Retrieves the text value that will be set on the textbox if this assist is selectedvoid
render(T object, Response response, String criteria)
Render the html fragment for the given completion object.protected abstract void
renderChoice(T object, Response response, String criteria)
Render the visual portion of the assist.void
renderFooter(Response response, int count)
Render the html footer fragment for the completion.void
renderHeader(Response response)
Render the html header fragment for the completion.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer
detach
-
-
-
-
Constructor Detail
-
AbstractAutoCompleteRenderer
public AbstractAutoCompleteRenderer()
-
-
Method Detail
-
render
public void render(T object, Response response, String criteria)
Description copied from interface:IAutoCompleteRenderer
Render the html fragment for the given completion object. Usually the html is written out by callingResponse.write(CharSequence)
.- Specified by:
render
in interfaceIAutoCompleteRenderer<T>
- Parameters:
object
- completion choice objectresponse
- response objectcriteria
- text entered by user so far
-
renderHeader
public void renderHeader(Response response)
Description copied from interface:IAutoCompleteRenderer
Render the html header fragment for the completion. Usually the html is written out by callingResponse.write(CharSequence)
.- Specified by:
renderHeader
in interfaceIAutoCompleteRenderer<T>
-
renderFooter
public void renderFooter(Response response, int count)
Description copied from interface:IAutoCompleteRenderer
Render the html footer fragment for the completion. Usually the html is written out by callingResponse.write(CharSequence)
.- Specified by:
renderFooter
in interfaceIAutoCompleteRenderer<T>
count
- The number of choices rendered
-
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 useResponse.write(CharSequence)
- Parameters:
object
- current assist choiceresponse
-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 returnsnull
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
-
-