Overriding Actions to support help and redirecting to URLs

Sometimes you may want to redirect a user to a different site or open a new document in a browser window. Suppose your application uses Java Help or simply launches IE with the help index when a user selects Help/Contents from the menu. When the application is web-enabled thru WebCream and is viewed as a web site, the help should be simple HTML in a new window. There's no need to launch any windows or applications on the server because the user already has a browser. WebCream supports this functionality thru "overriding actions".

An "action" in WebCream is a command sent by the user thru the browser. For example, if a user clicks on a button on the page, the page is submitted and the action is "button click". If the user selected a menu item the action is a menu command. By default, WebCream would emulate the action for the application so that the application can respond. However, WebCream also allows to override the action to trigger a different response. Let's use the example above to demonstrate how to override actions. Our sample application has a Help menu with Contents menu item. It also has a Help button in the Login dialog that invokes contents sensitive help for that dialog.

Action overrides are specified in the application properties file with "window." prefix. The format for the key is "window.<Window_Title>.<action_spec>". Window_Title is the title of the Window with the spaces replaced with _. For example, if you have a dialog with a title "Login Dialog" then the key name will begin with "window.Login_Dialog". Note that the title is actually is actually treated as a substring of the window title when the matching is done. So even if you put "window.Login" it will still apply to the dialog. This is done to simplify configuration for cases where a portion of the title changes dynamically (for example, the current user name or the server name is displayed in the title of the application).

There are two types of action_spec, one for menu items and one for buttons. The format of the action specification for menu is "menu.<popupIndex>.<itemIndex>.action". For example, if the Help menu is the third popup menu in the menu bar and Contents is the first menu item in Help menu, then action_spec will be "menu.3.0.action" and the full key name for a window with title "Welcome" will be "window.Welcome.menu.3.0.action". The easiest way to find out the values for indexes is to look at the source of the page, generated by WebCream. Search by menu item text to find the HTML code that represents the menu item and check the value of "doSubmit()" parameter.

The format of the action specification for buttons is even simpler. It is "button.<text>.action" where <text> is the text of the button with spaces replaced with underscores. So if you have a help button which says "Help Me" then the action spec will be "button.Help_Me.action" and the full key name will be "window.Login_Dialog.button.Help_Me.action".

Now that we know how to identify the elements that we want to specify action for it is time to learn how to provide a new value. Currently WebCream supports only URLs as the value for overridden values. The logic is that if the action override is specified for an item, the value will be a URL of a new page that should be displayed in a new window. For the sake of our example, let's say we placed the help files to our company's website with URL "http://mycompany.com/help". We'll add the following two lines to the application configuration file:

window.Welcome.menu.3.0.action=http://mycompany.com/help
window.Login_Dialog.button.Help_Me.action=http://mycompany.com/help/LoginDialog.html

Note that you can override actions for any kind of action recognized by WebCream. This includes toolbar buttons, which do not have text but have tool tip help which is used by WebCream when matching action overrides with components.