Widget properties and functions

The Rich UI widgets are written in EGL; specifically, they are EGL handler parts with the RUIWidget stereotype. You can learn the properties and functions that are available for a widget type in any of the following ways:

Always use dot syntax to access a given function or property; for example, myWidget.myFunction() or myWidget.myProperty.

Properties available for most widgets

Widget properties are fields that are available to your code at run time. Most other EGL properties are available only to EGL system code and are not available at run time.

Style-related properties, such as class and style are available for all widgets, as described in "Widget styles."

You might use the following properties to develop business applications:
  • children provides access to an array of subordinate widgets, if any; for details, see the "Children property and related functions" section in this topic.
  • class identifies a cascading style sheet (CSS) class that is used when displaying the widget.
  • disabled takes a Boolean that indicates whether the widget is disabled. A disabled widget cannot respond to events and, on most browsers, its text appears in grey.
  • id takes a string that is used to assign or retrieve an ID for a specific widget. You can use the ID in a cascading style sheet (CSS) to identify the style characteristics of that widget. Also, if you are integrating EGL with JavaScript™ libraries, you can use this property to assign an ID for the JavaScript logic to use.

    If the widget (for example, a box) corresponds to a DOM subtree rather than to a specific DOM element, the ID is for the topmost DOM element in the subtree. For an introduction to the DOM, see "Understanding how browsers handle a Rich UI application."

  • position specifies the meaning of the x and y coordinates of the widget and takes one of the following values:
    static
    The x and y coordinates of the widget are ignored, as is the default behavior. The displayed position changes if you first set the x and y values when the position value is static and then change the position value.
    absolute
    The x and y coordinates of the widget are relative to the top left of the browser window; those coordinates are not affected by the alignment value.
    relative
    The x and y coordinates of the widget are relative to the top left of the parent. If the parent of the widget is the document element, the coordinates are relative to the top left of the viewable area of the browser.
  • readOnly is a Boolean that indicates whether the user can change the content of a text field or text area.
  • tabIndex takes an integer that identifies the placement of the widget in a tab order. For example, a widget that is assigned a tabIndex value of 2 receives focus after the user tabs away from a widget that has a tabIndex value of 1. You can use numbers such as 10 and 20 (rather than 1 and 2) to allow for the later addition of other widgets.

    The default tab order is browser specific.

  • x and y values are integers that refer to the x-y coordinate of the widget. The meaning of that coordinate varies in accordance with the value of the position property. As suggested in the description of the position property, the graphical origin is either the top left of the browser window or the top left of a parent widget. The following rules apply:
    • The x value is positive to the right of the origin and negative to the left
    • The y value is positive below the origin and negative above

    You can place a widget outside of its parent and outside of the viewable area.

  • zIndex takes an integer that identifies the position of the widget, its nearness to the front, in relation to other widgets at the same x and y location. A widget with a relatively large zIndex value (for example, 4) is closer to the front than a widget with a relatively small zIndex value (for example, 2). The zIndex value has no effect when the value of position is static.
You might use the following properties to develop Widget types:
  • innerHTML is a string that you can use to assign or retrieve the HTML within a container, such as a div, floatLeft, or floatRight widget.
  • innerText is a string that you can use to assign or retrieve text within a container. You can use innerText to provide a text property that is specific to the type.
  • logicalParent is used for developing Widget types that are containers. When writing the code that adds children to the container, you set the logicalParent property so that it refers to the appropriate parent DOM element. For an introduction to the DOM, see "Understanding how browsers handle a Rich UI application."

    For example, in relation to the child of a box, the parent property refers not the box, but to a DOM TD element within a DOM Table element. However, the logicalParent property refers to the DOM Div element that represents the box and is the parent of the DOM Table element.

    parent is for Widget-type development and provides access to a parent DOM element. For an introduction to the DOM, see "Understanding how browsers handle a Rich UI application."
You might use the following properties to interact with users who read Arabic or Hebrew:
  • numericSwap takes a string ("Yes" or "No") that you can use to use Hindi numerals in Arabic. To use Hindi numerals, set numericSwap and reverseTextDirection to "Yes".
  • reverseTextDirection takes a string ("Yes" or "No") that indicates whether to reverse the text direction in the widget.
  • symmetricSwap takes a string ("Yes" or "No") that indicates whether to replace pairs of special characters to preserve the logical meaning of the presented text. If the value is "Yes", the effect is to replace paired characters such as <, >, [, and { with >, <, ], and }.
  • textLayout takes one of two strings: either "Visual" or "Logical":
    • If the setting is "Visual" and the user types "A" and then "B" (and if "A" and "B" are characters in a bidirectional language), the displayed characters are "AB". The order of display is the order of input, left to right, which is also the order in which the data is stored in local memory.
    • If the setting is "Logical", the displayed characters are "BA".

    In most cases, the setting "Visual" is appropriate for Arabic or Hebrew content that is derived from a machine that runs z/OS® or IBM® i.

  • widgetOrientation is for Arabic and Hebrew text. This property takes one of two strings: either "LTR" (left-to-right) or "RTL" (right to left). When you specify LTR, the widgets acts as a standard non-bidirectional widget. When you specify RTL, the widgets are mirrored: scroll bars for lists are displayed on the left, the text-typing orientation for input fields is right-to-left, and the text is right-aligned.
You might use the following properties to add accessibility:
  • ariaLive indicates the level of support that is provided for assistive technology: for screen readers that are able to notify users of updates to screen regions. To see the specifications for assistive technology, visit this Web site:

    http://www.w3.org/TR/wai-aria

    The ariaLive value is a quoted string ("off", "polite". "assertive", or "rude"), each of which is described in the "property: live" section in the specifications for assistive technology.

  • ariaRole indicates the role that is specified for the widget, as used for assistive technology. For details, see the assistive technology specifications.

    The ariaRole value is a quoted string, such as "button" or "listbox", each of which is described in the "Roles" section in the assistive technology specifications.

Functions for all widgets

A variety of getter and setter functions are used for creating new Widget types. Those functions are not described in this topic. For information about child-related functions, see the other sections of this topic.

The following functions are available for all widgets:
  • The fadeIn function causes the widget to fade in (to be presented slowly); the fadeOut function causes the widget to fade out (to be slowly made invisible):
    fadeIn (duration int in, callback EffectCallback)
    fadeOut (duration int in, callback EffectCallback)
    Each function takes two parameters:
    duration
    Number of milliseconds between the start and end of the process, whether the widget is fading in or fading out
    callback
    A reference to a function that is invoked as soon as the widget fades in or out. That function takes no parameters and has no return value. If you do not want to specify a function, set this argument to null:
    myButton.fadeOut(1000, null);
  • The focus function causes the widget to receive focus:
    focus()

    For example, a button in focus is highlighted, and the user's press of the ENTER key is equivalent to the user's click of the button. A text field that is in focus (if not read-only) includes a cursor so that the user can enter data by typing a printable character without first tabbing to the field.

    The user can press TAB repeatedly to cycle through the available fields. With each keypress, the focus moves either to the next application field or to a field on the browser; for example, to the Web address field.

    Here is an example invocation of focus:
    myButton.focus();
  • You can use the morph function to change the display of a widget over time. The function repeatedly calls one of your functions; in this way, your code specifies the behavior that is caused by the runtime invocation:
    morph (duration int in, callback EffectCallback, morphFunction MorphFunction )
    The function takes three parameters:
    duration
    Number of milliseconds between the start and end of the process.
    callback
    A reference to a function that is invoked as soon as the process is complete. That function takes no parameters and has no return value. If you do not want to specify a function, set this second argument to null.
    customMorphFunction
    A reference to a custom morph function, which is a function that is invoked repeatedly during the duration mentioned earlier. The custom morph function takes two parameters: the widget that is being changed and a float that is assigned by the EGL runtime. The float is a fraction between 0 and 1 and reflects the progress toward the end of the duration. At each invocation of the custom morph function, the value of that float is larger. That fraction is based on a calculation of how many times the custom morph function is invoked, given the duration that is available and the amount of time that is required to run the custom logic. The custom morph function has no return value.
    Here is an example:
    myButton.morph(1000, null, myCustomMorphFunction);
  • You can use the resize function to change the size of a widget over time:
    resize (width int in, height int in,
           duration int, callback EffectCallback)
    The function takes four parameters:
    width
    The desired final width, in pixels.
    height
    The desired final height, in pixels.
    duration
    Number of milliseconds between the start and end of the process.
    callback
    A reference to a function that is invoked as soon as the process is complete. That function takes no parameters and has no return value. If you do not want to specify a function, set this argument to null.
    Here is an example:
    myButton.resize(100, 100, 1000, myFunction);
  • The select function causes a widget to receive focus; if the widget is a text field or text area, the text is selected (at least on most browsers). The function does not have parameters:
    select()
    Here is an example invocation of select:
    myTextField.select();

Children property and related functions

A subset of widgets includes the children property, which specifies an array of subordinate widgets. Every element in the array refers to a named widget or to an anonymous one, as described here:
  • A named widget is declared outside the children array, as is the case for every widget in the following code:
    myInTextField TextField{};
    myButton Button{ text = "Input to Output", onClick ::= click };
    myOutTextField TextField{};
    
    myBox Box{ columns = 3, 
                 children = [ myInTextField,  myButton, myOutTextField ]};

    If the array references a named widget many times, only the last reference is used, and the other references are ignored.

  • An anonymous declaration starts with the keyword new, cannot be referenced in any of your code, and can be used to create a widget at the moment you are thinking about the placement of a widget:
    myInTextField TextField{};
    myTextOutField TextField{};
    
    myBox box{columns=3, 
              children=[myInTextField,
                        new Button{ text = "Input to Output", onClick ::= click},
                        myOutTextField]};
In many cases, a parent widget is a Box or Div type, and the placement of the children widgets is affected by the parent type:
  • A Box widget includes the columns property; the value of that property specifies the default placement of each widget that is listed in the children array. For example, if columns=1, the widgets that are listed in the array are displayed in a single vertical column. If columns=2, every second widget is displayed in the second column, and the subsequent widget (for example, the third in the array) is displayed in the first column of a new row.

    If the value of columns is n, the widget at position n+1 of the array is displayed in the first column of a new row. If you do not specify a columns value, the children of the Box widget extend to the right.

  • The children of a Div widget extend to the right, with a horizontal scroll bar (if necessary) to provide access to widgets that extend to the right of the viewable area.

Div widgets that are children of another widget are displayed vertically, one underneath the previous.

You can reassign the value of children in any function and thereby change the Web page. You can also reassign the value of initialUI in the on-construction function. For example, if you have declared these widgets, the following syntax is valid:
   myBox.children = [myInTextField, myButton02, myOutTextField];
Although you can reassign a children (or initialUI) array, do not make changes by using dynamic array functions, such as appendElement or the operator ::=. Instead, use the appendChild, appendChildren, removeChild, and removeChildren widget-specific functions . Here is an example, assuming you have declared the widgets specified:
Function myFirstFunction(){} 
   myBox.appendChild(myOtherButton);
   myBox.appendChildren([myOtherTextField, myOtherButton02]);
   myBox.removeChild(myOtherButton);
   myBox.removeChildren();
end
You can also add or remove children from the top DOM element:
document.body.appendChild(myOtherButton);
document.body.appendChildren([myOtherTextField, myOtherButton02]);
document.body.removeChild(myOtherButton);
document.body.removeChildren(); 

The appendChild and removeChild functions each accept a single widget; appendChildren accepts an array of widgets and removeChildren takes no arguments. In the case of appendChild or appendChildren, the widget declarations can be anonymous or named. In the case of removeChild, the widget declarations must be named.

The effect of assigning a widget to a different parent

A specific widget can be the child of only one other widget (or of the document body, as shown in a later example). If a widget has a parent, you can cause the widget to be the child of a different parent. This reassignment is referred to as re-parenting the child widget.

Consider the following declaration of myTopBox, which is the parent of two other boxes:
   myTopBox Box{padding = 8, columns = 1, backgroundColor = "Aqua",
      children =[myBox02, myBox03 ]};
Assume that the preceding declaration is in a Rich UI handler that makes myBox03 the only element in the initialUI array:
handler MyTest type RUIhandler{initialUI =[myBox03]}

At run time, the assignment to initialUI is handled after the declaration of myTopBox. The effect is that myBox03 is re-parented to the document body, leaving myTopBox with only one child, myBox02.

Your code might add myTopBox to the Web page in response to a runtime event, such as a user's button click. You can see the effect by running the following code and clicking the button:
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 MyTest type RUIhandler{initialUI =[myBox03]}
 
   myTopBox Box{padding = 8, columns = 1, backgroundColor = "Aqua", 
      children =[myBox02, myBox03 ]};
 
   myBox02 Box{padding = 8, columns = 2, backgroundColor = "DarkGray", 
      children =[myHelloField ]};
 
   myBox03 Box{padding = 8, columns = 3, backgroundColor = "CadetBlue", 
      children =[myInTextField, myButton, myOutTextField] };
 
   myHelloField TextField{readOnly = true, text = "Hello"};
   myInTextField TextField{};
   myButton Button{text = "Input to Output", onClick ::= click};
   myOutTextField TextField{};
 
   function click(e EVENT in)
      document.body.appendChildren([myTopBox]);		
   end
end

Removing all children from the document body

Consider the following statement:
   document.body.removeChildren();
This statement causes two results:
  • All children widgets are removed from the Web page.
  • Access to the external style sheet, if any is removed. Style sheets are described in "Widget styles."
If you want to remove children from the document body without removing access to the external style sheet, remove specific children:
   document.body.removeChild(myBox);

Feedback