package net.databinder.components;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.IHeaderResponse;

/*
 * Databinder: a simple bridge from Wicket to Hibernate
 * Copyright (C) 2006  Nathan Hamblen nathan@technically.us

 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * Attaches itself to the onchange event for a TextField or TextArea, and enhances that
 * event to fire not just when focus changes but also when keyboard input pauses. This
 * is effected in JavaScript, with a timer that resets when the onkeyup event fires.
 * @author Nathan Hamblen
 *
 */
public abstract class AjaxOnKeyPausedSubmitter extends AjaxFormSubmitBehavior {

	private static final ResourceReference JAVASCRIPT = new ResourceReference(
			AjaxOnKeyPausedSubmitter.class, "AjaxOnKeyPausedUpdater.js");

	/**
	 * Binds to onchange.
	 */
	public AjaxOnKeyPausedSubmitter() {
		super("onchange");
	}

	/**
	 * Adds needed JavaScript to header.
	 */
	@Override
	public void renderHead(IHeaderResponse response) {
		super.renderHead(response);
		response.renderJavascriptReference(JAVASCRIPT);
	}

	/**
	 * Adds JavaScript listeners for onkeyup and onblur.
	 */
	@Override
	protected void onComponentTag(ComponentTag tag) {
		super.onComponentTag(tag);
        tag.put("onkeyup", "AjaxOnKeyPausedTimerReset(this);");
        tag.put("onblur", "AjaxOnKeyPausedTimerCancel();");
	}
}

@@ -73,16 +73,65 @@
 erence;%0A
+import org.apache.wicket.ajax.AjaxRequestTarget;%0A
 import o
@@ -2237,11 +2237,242 @@
 );%22);%0A%09%7D
+%0A%0A%09/**%0A%09 * Does nothing; override to respond to errors in the submitted form. (Submit on%0A%09 * pause is probably not a good match for forms that need validation.)%0A%09 */%0A%09@Override%0A%09protected void onError(AjaxRequestTarget target) %7B%0A%09%7D
 %0A%7D%0A

add onError base method