< Previous | Next >

Lesson 9: Embed the calculation history handler in the application

To add the calculation history handler to your page, you must change the results portlet and the main portal.

Change the results portlet

As of the end of the previous lesson, the CalculationResultsHandler handler subscribes to a single event: mortgageApplication.mortgageCalculated. When that event occurs, the handler updates and re-displays the pie chart. However, the user might select a row in the history portlet and cause a different event to be published: mortgageApplication.mortgageResultSelected. If CalculationResultsHandler subscribes to that event, too, the handler can respond to the user's selection in the same way, by updating and re-displaying the pie chart.

The simplest way to subscribe to both events is to use the asterisk (*), which is a wildcard character that represents any event in a set of events. Do as follows:

  1. In the Rich UI editor, open the CalculationResultsHandler.egl file and switch to the Source view.
  2. In the start() function, find the following line:
    InfoBus.subscribe("mortgageApplication.mortgageCalculated", displayChart);
  3. Replace the lowest-level qualifier in the event name with the asterisk:
    InfoBus.subscribe("mortgageApplication.*", displayChart);
    EGL now calls the displayChart function whenever an event occurs if the name of the event begins with mortgageApplication..
  4. Save and close the file.

Change the main portal

For the history portlet, add lines that are similar to the lines for the other two portlets:

  1. In the Rich UI editor, open the MainHandler.egl file and click the Source tab.
  2. Immediately below the resultsHandler declaration, add a similar declaration for historyHandler:
    historyHandler CalculationHistoryHandler{};
  3. Immediately below the resultsPortlet declaration, add a similar declaration for historyPortlet:
    historyPortlet Portlet{children = [historyHandler.historyResults_ui], 
    			title = "History", canMove = TRUE, canMinimize = TRUE};
  4. In the start function, below the existing calls to addPortlet, add the new portlet to the portal:
    	mortgagePortal.addPortlet(historyPortlet, 1);
  5. As you did with resultsPortlet, set historyPortlet to be minimized initially:
    	historyPortlet.minimize();
  6. Add code for historyPortlet to the end of restorePortlets() function:
    		if(historyPortlet.isMinimized())
    			historyPortlet.restore();
    		end	
  7. Save the file. If you see errors in your source file, compare your code to the file contents in Finished code for MainHandler.egl after Lesson 9.

Test the portal

Test the main portal to make sure that the new history portlet is displayed and works correctly.
  1. At the bottom of the editor, click Preview. EGL displays the main portal and the three subsidiary portlets.
  2. Click Calculate. An animated image indicates that work is in progress. When the calculation finishes, the pie chart and history are displayed.
    The restored results portlet shows the pie chart.
  3. Change the term of the mortgage to 5 years and click Calculate again. A row is added to the history list.
  4. Click a cell in the first row of the history list.
    The first row of the history list contains the 30-year calculation.
  5. The pie chart displays the values for the row selected in the history list.
    The updated pie chart has the values from the first calculation.

Lesson checkpoint

You learned how to subscribe to multiple, similarly named events.

In the next lesson, you add a portlet to display a map of mortgage companies that are in a specified area of the United States.

< Previous | Next >

Feedback