Referring to windows and components in WebCream

WebCream allows referring to windows and components such as buttons and text fields of your application using names. This can come handy when configuring application properties or fine-tuning multi-threading. Because names are used as entries in configuration files, they follow the general rules of identifier naming for example they can not have spaces. If a name has spaces, the spaces are replaced with underscores (_). For example to refer to a window with title "Please Login" you would use Please_Login. Leading and trailing spaces are simply truncated, so " Please Login " is still referred to as Please_Login.

Referring to windows
Windows are dialogs and frames displayed by the application. You refer to windows using the title that is displayed in the title bar of AWT or Swing window. The reference can be a substring of the window title, so if the title of your window changes depending on the server state or the host the client is connected to, you can use the part of the title that is constant. Regular expressions can be used for the ultimate flexibility (see more below). The table below shows examples of window titles and valid references to it
Window TitleValid Reference
LoginLogin
Please LoginPlease_Login
.*Login
Login to ACME.COMLogin_to_ACHME.COM
Login_to_
*
ACME.COM - Please LoginPlease_Login

Referring to components
In order to refer to a component you have to specify the window it is in, and an identifier which will be a component name. The general format for a component reference is <window-reference>.component.<component-name>. Window references are described above. Component names depend on the component type and are obtained using the table below as a guideline
Component Typehtml.humanComponentNames=truehtml.humanComponentNames=false
javax.swing.AbstractButton
(JButton, JRadioButton, JCheckBox, JToggleButton)
getText()getClassName() + hashCode()
java.awt.ButtongetLabel()getClassName() + hashCode()
javax.swing.JMenuItem<submenuId>.<itemId>getClassName() + hashCode()
java.awt.MenuItem<submenuId>.<itemId>getClassName() + hashCode()
All other java.awt.ComponentsgetName()getClassName() + hashCode()

Menu items follow a slightly different naming scheme. Instead of relying on the menu item text, indexes of submenus and menu items are used to uniquely identify the item. The easiest (and probably the only sensible) way of finding out what those indexes are is to let WebCream generate a page for the window with the menu, and then look at the page source. Find the text of the menu item and look at the doSubmit() JavaScript function. As a parameter it takes the action string that contains menu indexes. Take that string and replace / with . and you are good to go.

All other components can be referred to only if they have been given a name using setName() method of java.awt.Component. If no name has been given to a component, WebCream will automatically name it based on the class and a hashcode. However, those names are not consistent and can be different each time you restart the application. The table below shows some examples of referring to components in a dialog with title "Login" with humanComponentNames=true
Component typeName textReference
javax.swing.JButtonOKwindow.Login.component.JButton_OK
javax.swing.JToggleButtonTracing Offwindow.Login.component.JToggleButton_Tracing_Off
javax.swing.JMenuItemExit the applicationwindow.Login.component.JMenuItem_2.3

Regular Expressions
WebCream supports regular expressions in defining window and component names. For instance, to refer to all windows that have "Save" in their title ("Confirm Save", "Save", "Save Record") one can use

    window.*Save.*
For instance, to enabled all buttons with "Save" or "save" in the title ("Save Person", "Do you want to save?") that are in a window with "Save" in the title one can use
    window.*Save.*.button.(S|s)ave.enabled=true
To enable dynamic events for all components of class MyButton one can use
    window.*.component.MyButton.enabled=true