package wicket.extensions.ajax.markup.html.autocomplete;

import wicket.RequestCycle;
import wicket.Response;
import wicket.ajax.AbstractDefaultAjaxBehavior;
import wicket.behavior.AbstractAjaxBehavior;
import wicket.markup.html.PackageResourceReference;

/**
 * @since 1.2
 * 
 * @author Janne Hietam&auml;ki (jannehietamaki)
 */
public abstract class AbstractAutoCompleteBehavior extends AbstractAjaxBehavior
{
        private static final PackageResourceReference AUTOCOMPLETE_JS = new PackageResourceReference(AutoCompleteBehavior.class, "wicket-autocomplete.js");
        private static final PackageResourceReference AJAX_JS = new PackageResourceReference(AbstractDefaultAjaxBehavior.class, "wicket-ajax.js");

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected String getImplementationId()
	{
	    return "wicket-default-autocomplete";
	}

	protected void onBind()
	{
		getComponent().setOutputMarkupId(true);
	}

	protected void onRenderHeadInitContribution(Response response)
	{
	    super.onRenderHeadInitContribution(response);
	    writeJsReference(response, AJAX_JS);
	    writeJsReference(response, AUTOCOMPLETE_JS);
	}

	protected void onComponentRendered()
	{
		Response response=getComponent().getResponse();
		final String id = getComponent().getMarkupId();
		response.write("<script type=\"text/javascript\">");
		response.write("new WicketAutoComplete('"+id+"','"+getCallbackUrl()+"');");
		response.write("</script>");
	}

	/**
	 * @see wicket.behavior.IBehaviorListener#onRequest()
	 */
	public final void onRequest()
	{
		final RequestCycle requestCycle = RequestCycle.get();
		final String val = requestCycle.getRequest().getParameter("q");
		onRequest(val, requestCycle);
	}

	/**
	 * Callback for the ajax event generated by the javascript. This is
	 * where we need to generate our response.
	 * 
	 * @param input
	 *            the input entered so far
	 * @param requestCycle
	 *            current request cycle
	 */
	protected abstract void onRequest(String input, RequestCycle requestCycle);
}

package wicket.extensions.ajax.markup.html.autocomplete;

import wicket.RequestCycle;
import wicket.Response;
import wicket.ajax.AbstractDefaultAjaxBehavior;
import wicket.behavior.AbstractAjaxBehavior;
import wicket.markup.html.PackageResourceReference;

/**
 * @since 1.2
 * 
 * @author Janne Hietam&auml;ki (jannehietamaki)
 */
public abstract class AbstractAutoCompleteBehavior extends AbstractAjaxBehavior
{
        private static final PackageResourceReference AUTOCOMPLETE_JS = new PackageResourceReference(AutoCompleteBehavior.class, "wicket-autocomplete.js");
        private static final PackageResourceReference AJAX_JS = new PackageResourceReference(AbstractDefaultAjaxBehavior.class, "wicket-ajax.js");

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected String getImplementationId()
	{
	    return "wicket-default-autocomplete";
	}

	protected void onBind()
	{
		getComponent().setOutputMarkupId(true);
	}

	protected void onRenderHeadInitContribution(Response response)
	{
	    super.onRenderHeadInitContribution(response);
	    writeJsReference(response, AJAX_JS);
	    writeJsReference(response, AUTOCOMPLETE_JS);
	}

	protected void onComponentRendered()
	{
		Response response=getComponent().getResponse();
		final String id = getComponent().getMarkupId();
		response.write("<script type=\"text/javascript\"><!--");
		response.write("new WicketAutoComplete('"+id+"','"+getCallbackUrl()+"');");
		response.write("--></script>");
	}

	/**
	 * @see wicket.behavior.IBehaviorListener#onRequest()
	 */
	public final void onRequest()
	{
		final RequestCycle requestCycle = RequestCycle.get();
		final String val = requestCycle.getRequest().getParameter("q");
		onRequest(val, requestCycle);
	}

	/**
	 * Callback for the ajax event generated by the javascript. This is
	 * where we need to generate our response.
	 * 
	 * @param input
	 *            the input entered so far
	 * @param requestCycle
	 *            current request cycle
	 */
	protected abstract void onRequest(String input, RequestCycle requestCycle);
}

fix for bug [ 1498807 ] IE throws Operation aborted with autocomplete