Next, you must configure the JSF handler to use the input
from the radio button to decide which search function to use.
- Right-click a blank area of the page and click Edit
Page Code from the menu. The file customersearch.egl
opens in the editor.
- With the variable declarations at the top of the handler,
add this line of code:
andOr CHAR(3);
Later, you will bind this variable to the radio buttons.
It holds the value "AND" or "OR," depending on which radio button
you select on the page.
- Replace the function call to NameAndStateSearch_And with
the following code:
if (andOr == "AND")
SearchLibrary.NameAndStateSearch_And(
searchTerms.LastName,
searchTerms.State, searchResults);
else
SearchLibrary.NameAndStateSearch_Or(
searchTerms.LastName,
searchTerms.State, searchResults);
end
The entire function now looks like the following code:
function searchFunction()
searchTerms.LastName = searchTerms.LastName+"%";
if (andOr == "AND")
SearchLibrary.NameAndStateSearch_And(
searchTerms.LastName,
searchTerms.State, searchResults);
else
SearchLibrary.NameAndStateSearch_Or(
searchTerms.LastName,
searchTerms.State, searchResults);
end
resultMessage = " customer(s) found.";
numberOfResults = searchResults.getSize();
end
This function now calls different functions
depending on the value of the andOr variable.
- Save and close the file.
- Return to the customersearch.jsp page.
- From the Page Data view, bind the andOr - char(3) variable
to the radio button group by dragging it onto the radio button group
on the page.
- Bind the searchFunction() function
to the Submit button on the page.
- Save the page.
- Test the page.
When you test the page, try using the new radio button
functions. You must select one of the radio buttons for the search
page to work properly.
This search page is still difficult
to use because there are not many records in the sample database and
many states to guess from. In the next lesson, you will change the
State input field to a combo box that lists all of the states used
in the database.
Here is the complete code of the customersearch.egl
file. If you see any errors marked by red X symbols in the file, make
sure your code matches the code in this file:Completed customersearch.egl file after lesson 3.