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

Information Technology Auditor (PA)
Next Step Systems
US-PA-Wayne

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
Popular JavaScript Framework Libraries: An Overview - Part 3
Accessing Your MySQL Database from the Web with PHP
Working with the DOM Stylesheets Collection
internet.com site name
Review: Lenovo ThinkPad SL300
OCZ PC3-10666 Gold 2x1GB Review
Apple Recommends Antivirus for Macs


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

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES