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;
 
 
This behavior builds on top of AbstractAutoCompleteBehavior by introducing the concept of a IAutoCompleteRenderer to make response writing easier.

Parameters:
Author(s):
Igor Vaynberg (ivaynberg)
Janne Hietamäki (jannehietamaki)
Since:
1.2
See also:
IAutoCompleteRenderer
 
 public abstract class AutoCompleteBehavior extends AbstractAutoCompleteBehavior
 {
 	private static final long serialVersionUID = 1L;
 
 	private final IAutoCompleteRenderer renderer;

Constructor

Parameters:
renderer renderer that will be used to generate output
 
 	{
 		this(rendererfalse);
 	}


Constructor

Parameters:
renderer renderer that will be used to generate output
preselect highlight/preselect the first item in the autocomplete list automatically
 
 	public AutoCompleteBehavior(IAutoCompleteRenderer rendererboolean preselect)
 	{
 		this(renderernew AutoCompleteSettings().setPreselect(preselect));
 	}

Constructor

Parameters:
renderer renderer that will be used to generate output
settings settings for the autocomplete list
 
 	{
 		if (renderer == null)
 		{
 			throw new IllegalArgumentException("renderer cannot be null");
 		}
 		if (settings == null)
 		{
 			settings = new AutoCompleteSettings();
 		}
 		this. = renderer;
 		this. = settings;
 	}
 
 	protected final void onRequest(final String valRequestCycle requestCycle)
 	{
 		IRequestTarget target = new IRequestTarget()
 		{
 			public void respond(RequestCycle requestCycle)
 			{
 				WebResponse r = (WebResponse)requestCycle.getResponse();
				// Determine encoding
				final String encoding = Application.get()
				r.setContentType("text/xml; charset=" + encoding);
				// Make sure it is not cached by a
				r.setHeader("Expires""Mon, 26 Jul 1997 05:00:00 GMT");
				r.setHeader("Cache-Control""no-cache, must-revalidate");
				r.setHeader("Pragma""no-cache");
				Iterator comps = getChoices(val);
				while (comps.hasNext())
				{
					final Object comp = comps.next();
					.render(comprval);
				}
			}
			public void detach(RequestCycle requestCycle)
			{
			}
		};
		requestCycle.setRequestTarget(target);
	}

Callback method that should return an iterator over all possible choice objects. These objects will be passed to the renderer to generate output. Usually it is enough to return an iterator over strings.

Parameters:
input current input
Returns:
iterator over all possible choice objects
	protected abstract Iterator getChoices(String input);
New to GrepCode? Check out our FAQ X