org.apache.wicket.extensions.ajax.markup.html.autocomplete
Class AbstractAutoCompleteRenderer

java.lang.Object
  extended by org.apache.wicket.extensions.ajax.markup.html.autocomplete.AbstractAutoCompleteRenderer
All Implemented Interfaces:
java.io.Serializable, IAutoCompleteRenderer, IClusterable
Direct Known Subclasses:
AbstractAutoCompleteTextRenderer

public abstract class AbstractAutoCompleteRenderer
extends java.lang.Object
implements IAutoCompleteRenderer

A renderer that abstracts autoassist specific details and allows subclasses to only render the visual part of the assist instead of having to also render the necessary autoassist javascript hooks.

Since:
1.2
Author:
Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Constructor Summary
AbstractAutoCompleteRenderer()
           
 
Method Summary
protected  java.lang.CharSequence getOnSelectJavascriptExpression(java.lang.Object 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  java.lang.String getTextValue(java.lang.Object object)
          Retrieves the text value that will be set on the textbox if this assist is selected
 void render(java.lang.Object object, Response response, java.lang.String criteria)
          Render the html fragment for the given completion object.
protected abstract  void renderChoice(java.lang.Object object, Response response, java.lang.String criteria)
          Render the visual portion of the assist.
 void renderFooter(Response response)
          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
 

Constructor Detail

AbstractAutoCompleteRenderer

public AbstractAutoCompleteRenderer()
Method Detail

render

public final void render(java.lang.Object object,
                         Response response,
                         java.lang.String criteria)
Description copied from interface: IAutoCompleteRenderer
Render the html fragment for the given completion object. Usually the html is written out by calling Response.write(CharSequence).

Specified by:
render in interface IAutoCompleteRenderer
Parameters:
object - completion choice object
response - response object
criteria - text entered by user so far
See Also:
IAutoCompleteRenderer.render(java.lang.Object, org.apache.wicket.Response, String)

renderHeader

public final void renderHeader(Response response)
Description copied from interface: IAutoCompleteRenderer
Render the html header fragment for the completion. Usually the html is written out by calling Response.write(CharSequence).

Specified by:
renderHeader in interface IAutoCompleteRenderer
See Also:
IAutoCompleteRenderer.renderHeader(org.apache.wicket.Response)

renderFooter

public final void renderFooter(Response response)
Description copied from interface: IAutoCompleteRenderer
Render the html footer fragment for the completion. Usually the html is written out by calling Response.write(CharSequence).

Specified by:
renderFooter in interface IAutoCompleteRenderer
See Also:
IAutoCompleteRenderer.renderFooter(org.apache.wicket.Response)

renderChoice

protected abstract void renderChoice(java.lang.Object object,
                                     Response response,
                                     java.lang.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 java.lang.String getTextValue(java.lang.Object 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 java.lang.CharSequence getOnSelectJavascriptExpression(java.lang.Object 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 StringBuffer js = new StringBuffer();
    js.append("wicketGet('street').value ='" + address.getStreet() + "';");
    js.append("wicketGet('zipcode').value ='" + address.getZipCode() + "';");
    js.append("wicketGet('city').value ='" + address.getCity() + "';");
    js.append("input"); // <-- do not use return statement here!
    return js.toString();
 }
 
example 2:
 protected CharSequence getOnSelectJavascript(Currency currency)
 {
    final StringBuffer js = new StringBuffer();
    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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.