The main component of a Rich UI application is a Rich UI Handler part, which is a handler with the stereotype RUIHandler. The Handler part places widgets on a web page and handles events such as a user's click of a button. The widgets and functions in one Handler part can be made available to others, as described in “Creating a Rich UI application with multiple handlers.”
import com.ibm.egl.rui.widgets.Box;
import com.ibm.egl.rui.widgets.Button;
import com.ibm.egl.rui.widgets.TextField;
import egl.ui.rui.Event;
handler ButtonTest01 type RUIhandler {initialUI = [ myTopBox ],
onConstructionFunction = initialization}
myHelloField TextField
{ readOnly = true, text = "Hello" };
myInTextField TextField{};
myButton Button{ text = "Input to Output", onClick ::= click };
myOutTextField TextField{};
myBox03 Box{ padding=8, columns = 3,
children = [ myInTextField, myButton, myOutTextField ],
backgroundColor = "CadetBlue" };
myBox02 Box{ padding=8, columns = 2, children = [myHelloField],
backgroundColor = "DarkGray"};
myTopBox Box{ padding=8, children = [ myBox02, myBox03 ],
columns = 1, backgroundColor = "Aqua" };
function initialization()
end
function click(e EVENT in)
myOutTextField.text = myHelloField.text + " " + myInTextField.text;
end
end
After the user types the word World in the lower left text box and clicks the button, the user interface is as follows:
The same example is used to explain the DOM tree; for details, see “Understanding how browsers handle a Rich UI application.”
Handler ButtonTest Type RUIHandler
{ children = [ui], cssFile = "buttontest/coolblue.css" }
Here
is an example CSS file: .EglRuiGridTable
{ border: 3px solid black; }
.EglRuiGridHeader
{ color:yellow;
background-color:red; }
.EglRuiGridCell
{ color:black;
background-color:aqua; }
If both the cssFile and includeFile properties are specified, the CSS content referenced by the cssFile property takes precedence. That content takes precedence because in the deployed HTML file, the <link> entry is embedded after the content referenced by the includeFile property.
For additional details about Rich UI support for styles, see “Widget styles.”
Handler ButtonTest Type RUIHandler
{ children = [ui], includeFile = "buttontest/coolblue.css" }
<script>
<!-- file contents here -->
</script>
<style type="text/css">
.EglRuiGridTable
{ border: 3px solid black; }
.EglRuiGridHeader
{ color:yellow;
background-color:red; }
.EglRuiGridCell
{ color:black;
background-color:aqua; }
</style>
<link REL="STYLESHEET" TYPE="text/css" href="css/dashboard.css">
In this example, a warning message indicates that the href value does not refer to an existing file. The warning exists because the development-time editor seeks the WebContent/MyFolder/css/dashboard.css file rather than the actual file, which is WebContent/css/dashboard.css. Ensure that the value of the <href> tag includes a path relative to the WebContent directory and ignore warning messages that indicate a need for a different path.
At run time, you can set a new theme by invoking ruiLib.setTheme() and can retrieve the name of the theme in use by invoking ruiLib.getTheme().
To use a theme, you must code statements that import the necessary CSS files into your CSS file. For details, see “Themes to use in your application.”
At run time, you can set a new title by invoking ruiLib.setTitle() and can retrieve the name of the title in use by invoking ruiLib.getTitle().
As shown, the box widgets include various properties; in particular, the children property. That property is the means by which the handler appends children and other descendants to the widgets specified in the initialUI array.