List Box Example

LANSA WAM

List Box Example

Following is an example of a list box with multiple selections plus a description of the techniques used to produce this result.

If you require only single selection in your list box, you should refer to the description of the allow_multi_selections and related properties.

The list box allows for multiple selections (via the standard Windows method of holding down the Shift or Ctrl keys when making selections). The 'Produce Report' button, when clicked, passes the selected entries into the WAM for processing.

Change the items selected in the list box and click the 'Produce Report' button. You will see a list of the selected entries in a list, similar to the following:

The List Definitions

Two lists are required to code the multi-select list box:

The first, #ListBox, drives the content of the list box. It will usually have two fields in it: a code field and a description field.

The second list, #Selected, has two uses. Entries can be added to it in the WAM to cause #ListBox entries to be pre-selected when the list box is displayed. It is also used to return the entries selected by the user to the WAM.

If you right-click on the ShowPage Webroutine and open it in the LANSA Editor, you'll see the list box and the push button. Click on the list box and display its properties by clicking on the Details tab:

The allow_multi_selections setting is self-explanatory: true() means that multi-selections are enabled, whilst false() ensures that only single selection is permitted.

  • The listname property holds the name of the working list used to populate the list box.
  • The codefield property is the name of the field in the listname list that holds the code value of the list entry (in this case, department code).
  • The captionfield property is the name of the field to be displayed in the list box (in this case, department description).

These entries are sufficient to get the list box populated and onto the web page.
The remaining two properties relate to the selection of entries in the list box:

  • The multi_select_listname property contains the name of the list that is to return the selected entries to the WAM.
  • The multi_select_codefield property is the name of the field in that list that is to hold the code value of the selected entry.

Building the Main List

Look at the ShowPage Webroutine in the source editor again:

Note the Web_maps for the two list box-related lists.

A simple Select loop is used to add all departments from the DEPTAB file to the main list, #ListBox.

Then, two entries are added to the #Selected list. This will pre-select the Administration and Information Systems departments in the list box when it's displayed.

Processing the Selected Entries

The ProduceReport Webroutine is invoked by the push button on the web page:

Again, note the Web_maps: the incoming list of selected entries (#Selected) and another, outgoing list (#Report). These are used to display a list of selected departments.