Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.wicket.extensions.ajax.markup.html.autocomplete;
 
 

Author(s):
Janne Hietamäki (jannehietamaki)
Since:
1.2
 
 public abstract class AbstractAutoCompleteBehavior extends AbstractDefaultAjaxBehavior
 {
 		AutoCompleteBehavior.class"wicket-autocomplete.js");
 
 	private static final long serialVersionUID = 1L;
 
 	protected boolean preselect = false;
 
 
 
 	public void renderHead(IHeaderResponse response)
 	{
 		super.renderHead(response);
 		final String id = getComponent().getMarkupId();
 		String initJS = constructInitJS();
 		response.renderOnDomReadyJavascript(initJS);
 	}
 
 	protected final String constructInitJS()
 	{
 		final String indicatorId = findIndicatorId();
 
 		StringBuffer sb = new StringBuffer();
 		sb.append("new Wicket.AutoComplete('")
 			.append("','")
 			.append("',")
 			.append(",");
 		if (Strings.isEmpty(indicatorId))
 		{
 			sb.append("null");
 		}
 		else
 		{
 		}
 		sb.append(");");
 		return sb.toString();
 	}
 
 	protected final String constructSettingsJS()
 	{
 		final StringBuffer sb = new StringBuffer();
 		sb.append("{preselect: ").append(.getPreselect());
 		sb.append(",maxHeight: ").append(.getMaxHeightInPx());
 		sb.append(",adjustInputWidth: ").append(.isAdjustInputWidth());
 		sb.append(",showListOnEmptyInput: ").append(.getShowListOnEmptyInput());
 		sb.append(",showListOnFocusGain: ").append(.getShowListOnFocusGain());
 		sb.append(",showCompleteListOnFocusGain: ").append(
 		if (.getCssClassName() != null)
 			sb.append(",className: '").append(.getCssClassName()).append('\'');
 		sb.append('}');
 		return sb.toString();
 	}

 
	protected void onBind()
	{
		// add empty AbstractDefaultAjaxBehavior to the component, to force
		// rendering wicket-ajax.js reference if no other ajax behavior is on
		// page
		{
			private static final long serialVersionUID = 1L;
			protected void respond(AjaxRequestTarget target)
			{
			}
		});
	}

Callback for the ajax event generated by the javascript. This is where we need to generate our response.

Parameters:
input the input entered so far
requestCycle current request cycle
	protected abstract void onRequest(String inputRequestCycle requestCycle);

	protected void respond(AjaxRequestTarget target)
	{
		final RequestCycle requestCycle = RequestCycle.get();
		final String val = requestCycle.getRequest().getParameter("q");
		onRequest(valrequestCycle);
	}
New to GrepCode? Check out our FAQ X