< 前へ

演習 6 の後の完成した customersearchAJAX.egl ファイル

次のコードは、演習 6 の後で完了したバージョンの customersearchAJAX.egl ファイルです。このファイル内にエラーがある場合 (赤の X 記号でマークされます) は、作成したコードがこのコードと一致していることを確認してください。
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

演習 6: 先行入力を使用したユーザーへの候補の表示に戻る。

< 前へ

フィードバック