In this lesson, you work directly with EGL source code, starting with an EGL library that you write. A library can contain constants, variables, and functions, any of which can be accessed by the different units of logic in your application. An important characteristic of a library is that changes to a variable are available to any unit of logic that accesses the library. However, the focus in this tutorial is on functions, which you place in a library to avoid having to maintain the same, widely used logic in multiple places.
To handle some commonplace issues, you can use the EGL Model View Controller (MVC) framework, which is provided by the com.ibm.egl.rui project. Although the initials "MVC" typically describe the different components of an enterprise application, the MVC framework in Rich UI concerns only the components of a user interface. Here, the model is a variable or record field, the view is a widget, and the controller is a declaration that oversees the transfer of data between the model and view. That transfer of data is sometimes automatic and is sometimes a response to a function invocation, as shown later.
The drag-and-drop actions of the previous lesson added not only controller declarations, but a form manager, which is a declaration that lets you treat other declarations as components of a single form. A form manager includes a set of form fields, each of which can include a label, a controller, and an error field.
EGL created a stub inputRec_form_Submit function. The intent is for the function to validate all the fields on the form and to “commit” them. The commit is part of the MVC implementation and means that the inputRec record is updated with the values in the widgets.
You will add code to call two other functions. The first function makes the processImage image visible and in this way tells the user that the application is working. The second function calls the service to calculate the mortgage payment.
if(inputRec_form.isValid())
inputRec_form.commit();
showProcessImage();
calculateMortgage();
else
errorLabel.text = "Input form validation failed.";
end

function showProcessImage()
processImage.visible = yes;
end
function hideProcessImage()
processImage.visible = no;
end
function calculateMortgage()
call mortService.amortize(inputRec)
returning to displayResults
onException handleException;
end
function displayResults(retResult MortgageCalculationResult in)
paymentLabel.text = MortgageLib.formatMoney(retResult.monthlyPayment as STRING);
inputRec_form.publish();
hideProcessImage();
end
Given that sequence of events, the form-level publish function is often invoked as it is here: in a callback function that receives data from a service.
Do as follows:
You are now ready to test the calculator.
In the next lesson, you create a pie chart to compare the total principal to the total interest in a given calculation.