< Previous

Completed customersearchAJAX.egl file after lesson 6

This code is the version of the customersearchAJAX.egl file completed after lesson 6. If you see any errors marked by red X symbols in the file, make sure your code matches this code:
package jsfhandlers;

import eglderbydb.data.Customer;

handler customersearch type JSFHandler
	{onConstructionFunction = onConstruction, 
	 onPrerenderFunction = onPrerender, 
 	 view = "customersearch.jsp",
 	 viewRootVar = viewRoot} 

	viewRoot UIViewRoot;
	lastNameInput STRING {TypeaheadFunction = suggestLastNames};
	allLastNames Customer[0];
	customerToDisplay Customer;

function onPreRender()
	get allLastNames with
		#sql{
			select
				LASTNAME
			from EGL.CUSTOMER
			group by
				LASTNAME
		};
end

	function suggestLastNames(typedCharacters STRING in) returns (STRING[])
		matchingLastNames STRING[0];
		oneCustomer Customer;
		oneCustomerName STRING;

		//This variable represents the characters the user has typed.
		typedCharacters = StrLib.upperCase(typedCharacters);

		//Compare the user input to the values in the database.
		for (counter INT from 1 to allLastNames.getSize())
			oneCustomer = allLastNames[counter];
			oneCustomerName = StrLib.upperCase(oneCustomer.LastName);

			if (StrLib.indexOf(oneCustomerName, typedCharacters) == 1)
				//This value starts with the same characters.
				//Add this value to the type-ahead suggestions.
				matchingLastNames.appendElement(oneCustomer.LastName);
			end

		end	
		return (matchingLastNames);
	end

	function displayCustomer()
		get customerToDisplay with
			#sql{
				select
					CUSTOMERID, FIRSTNAME, LASTNAME, PASSWORD, PHONE, 
					EMAILADDRESS, STREET, APARTMENT, CITY, "STATE", 
					POSTALCODE, DIRECTIONS
				from EGL.CUSTOMER
				where
					LASTNAME = :lastNameInput
			};
	end

end

Return to Lesson 6: Use type-ahead to prompt the user.

< Previous

Feedback