Consider what happens if you access the Eclipse web site and then one owned by a media company. Two different web pages are provided from remote servers, and you can click the Back and Forward buttons in your browser to revisit each of the sites.
In contrast, the main processing in a Rich UI application is solely in your browser. The application may render new content and may even access the server for visual updates, but in most cases, the Back and Forward buttons are either disabled or direct processing to other web site.
In Rich UI, you decide what on-screen content to identify as a separate web page. You enforce that decision by accessing functions in History, which is a Rich UI handler part provided with the product. By working with History, you can assign pages to the browser history at run time, and the user can use the Back and Forward buttons to access different pages in the application. Also, you can respond to the user's attempt to close the browser.
The browser-history mechanism does not save the state of a given web page. You need to code the behavior that makes sense for your application.
import com.ibm.egl.rui.history.History; import com.ibm.egl.rui.history.HistoryChanged; import com.ibm.egl.rui.history.OnBeforeUnloadMessageFunction; Handler MyApplication Type RUIHandler { onConstructionFunction=start } myHistory History {}; end
By declaring a variable based on History, you add #empty to the web address displayed in the user's browser. In regard to subsequent processing, empty is the name of the new page. The new page is added to an application-specific browser history, but not to the browser's own history, which retains only the original web address.
myHistory.addListener(myHistoryChanged);
Delegate HistoryChanged(newPageName String in) end
As shown, the event handler for the new-page event accepts a string. If you invoke addListener and reference a custom function, the custom function is invoked in the following cases: when the browser adds the initial page named empty, and when you add a subsequent page. In each case, the user's browser displays the web address and includes the page name, which is the address subset that is displayed subsequent to the pound sign (#); also, the EGL Runtime provides that page name to your function.
function myHistoryChanged(newPageName String in) myLabel.text = "History was changed. Current page name is "+ newPageName; end
You can register multiple new-page event handlers by running addListener multiple times. The referenced functions run in the order of registration. Even if you register the same function multiple times, all the registrations are in effect.
history.keepUserOnPage(stayHere);
Delegate OnBeforeUnloadMessageFunction() returns(String) end
As shown, the event handler for the close-browser event returns a string. That string is displayed in a dialog box that lets the user confirm or reverse the browser close.
function stayHere() returns(String) return ("Close the application?"); end
myHistory.addToHistory("myNewPage");
You can navigate to the previous page in your application. Here is the example code:
myHistory.goBack();
You can navigate to the next page in your application. Here is the example code:
myHistory.goForward();