<%-- Copyright 2004-2006 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html $Id: index.jsp,v 1.2 2006/06/23 17:05:40 basler Exp $ --%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@taglib prefix="ui" uri="http://java.sun.com/blueprints/ui/14" %> Address Form Using a AJAX JSF Component

Auto-Completion using JavaServer Faces and AJAX


This example shows how you can do real time auto-completion using AJAX interactions.

In the form below, enter a U.S. address. Two of the fields, city and state, offer auto completion from data residing on the server. Both fields are using the custom <ajax:completionField/> component.

The state field is using the component in a simple, straighforward way; it has a method binding to ApplicationBean.completeState which just returns a set of matching states that are displayed.

The city field on the other hand provides custom JavaScript handlers which take a server completion entry (which contains a city, state and zip code, returned by ApplicationBean.completeCity) and format the entries shown in the completion to only show city and state, and another handler which causes a chosen city to populate all three textfields for city, state and zip.

An obvious extension to this form would be to make the Zip field make asynchronous calls too, and have it populate the city and state field when the zip code is modified.








Java BluePrints | Sun Microsystems © 2006 Sun Microsystems Inc. All rights reserved. Use is subject to license terms.