search the site  

Enter search terms:


subscribe to newsletters   WebReference.com logo   WebReference.com
dev the Web
tip archive  •   about  •   contact  •   jobs  •   sitemap


[next]

How to Create an Ajax Autocomplete Text Field: Part 2

By Rob Gravelle

Digg This Add to del.icio.us

ASP 3.0/.NET Developer
Jupitermedia
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Welcome to Part 2 of the How to Create an Ajax Autocomplete Text Field series. In part one, we downloaded and configured some free development tools to help us manage the technologies that make up the Autocomplete text field. This week, we'll construct the The Fund Java class, which will act as a container for all the fund's properties. On the server, we'll store a collection of funds to be searched. Matching ones will be converted to a JSON array and returned to the browser for displaying in our Autocomplete list. We'll start with the Fund class because it has the least external dependencies and is a great way to show off Eclipse's automatic code generation.

Build Automatically
Fig. 1: Build Automatically

Some Useful Code Development Settings

Eclipse offers a couple of nifty features to make it easier to work with the Java files.

The first is the "Build Automatically" setting. It's under the "Project" menu. Selecting this item will cause Eclipse to build (compile) the file every time it's saved. That way, you won't save it in an invalid state (Figure 1).

Another relevant feature is the ability to set code formatting standards. All organizations have slightly different ways of formatting their code, so it's nice to be able to generate Java code that matches your preferred format. The facilities to do that in Eclipse are found under "Java: Code Style: Formatter" in the main "Preferences" dialog, under "Windows: Preferences..." on the main menu (See Figure 2).

I encourage you to create your own profile rather than change the existing ones. To create a new profile, click on the "New..." button. In the "New Profile" dialog, enter the name of your profile in the "Profile name" field. Mine is "RobG". You can choose from any preexisting profiles to use as the basis for your new one. The "Eclipse [built-in]" one is what is used by default. Make sure the "Open the edit dialog now" checkbox is checked so that you can make your changes right away (See Figure 3).

After you hit the "OK" button you'll be greeted by the massive "Profile" dialog! It allows you to modify a multitude of coding styles. For me, the most important are the brace positions. I like to have all opening and closing braces that span more than one line to be aligned vertically. To accomplish this, select, the "Braces" tab and chose the "Next line" option from each dropdown except the last one (See Figure 4).

Click the "OK" button on this dialog and the "Preferences"one to accept the changes and set your new profile as the active one.

Set up the Package Structure

com.webreference.autocomplete package
Fig. 7: com.webreference.autocomplete package

As you may already be aware, in Java it's commonplace to organize project files in subdirectories called packages. For instance, in the Canadian government, we use "ca.gc.<branch>" as the base for all projects. It's also customary to use the company's domain name, such as "com.widgets.". In our project, we are using JSON utility classes which reside in the "org.json" package. For the purpose of this exercise, we'll house our Autocomplete text field classes in a package called "com.webreference.autocomplete".

To create the packages, right click on the "Java Resources" branch in the "Project Explorer" pane. That brings up a popup menu of one item: "New." Hover the mouse pointer over that to bring up the second popup, which contains the "Package" item (See Figure 5).

Click on "Package" to bring up the "New Java Package" dialog (See Figure 6).

Type the entire "com.webreference.autocomplete" package name in the "Name" textbox and click on "Finish" to create the package structure (Figure 7).


[next]

Recent Articles

WebReference.com site name
Perl Pragma Primer
Implement Drag and Drop in Your Web Apps: Part 2
How to Create an Ajax Autocomplete Text Field: Part 5
internet.com site name
SQL Server 2005 Express Edition - Part 22 - Upgrading from Microsoft SQL Server Desktop Engine (MSDE)
Vyatta: Downgrades that Pay Off
NetMotion Brings Cross-Network Support to Wireless VoIP




JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES