Learning XPages Part 44 : Adding A Dropdown Combobox Lookup To A Field

In traditional notes client development
 our ‘location’ field would be a dropdown list of all the valid locations
created with a @dbColumn formula. In XPages we can duplicate this functionality
using the ‘ComboBox’ control.

Open your content_Person custom control
and drag in the ‘ComboBox’ control from the controls area on the right
, I’m going to put mine beside the ‘Location’ editbox control. First we
will set the ‘ReadOnly’ property to the exact same javascript code that
we used in the last part of the series so that you can only edit the field
if you are dealing with a new document.

On the data tab we will bind the control
to the ‘PersonDoc’ data source and the ‘Location’ field.

A picture named M2

We also have the ability to provide
a default value. I’ve decided to use the sessionScope.locationfilter variable
as that contains the value of the location we aere at when we clicked the
‘Create Person’ action button. It’s probably a good bet that the end user
went to the location of the person they wanted to create before clicking
that button. Click the diamond and enter ‘sessionScope.locationfilter()’
as the JavaScript to use.

In the properties for the combobox there
is a new property section called ‘Values’ and in here is where we specify
the different values that we want to appear in the dropdown box. You can
either hardcode in options using the ‘Add Item’ button or you can write
a formula using the ‘Add Formula Item’ button, You can even combine the
two if you want.

A picture named M3

For the formula item to work it needs
to return a string that consists of both labels and values that are separated
by a pipe | symbol and separated by a comma between each pair. Using your
knowledge of formula language we can very easily create this list.

In my lkp_Locations view I have created
a second column that displays the location name in the correct format with
the pipe symbol

A picture named M4

Then I simply clicked the ‘Add Formula
Item’ and entered in the following code :

@DbColumn("","lkp_Locations",2);

The first value of an empty string tells
the XPages processor that we are doing the lookup in the current database.
The second value is the name of the view that we are doing the lookup in
and the third value is the column number to return the values from start
at column number 1. In traditional formula language you could from 0 so
watch out for this slight change in the way the @DbColumn works.

Now saving our XPage and refreshing
shows us a nice dropdown list with it’s default value set to the current
location.

A picture named M5

Advertisement
Tagged with: , , , ,
Posted in None
Archives
%d bloggers like this: