So enough of the introduction, onto passing some Java to selectors.

There are two types of Collections you may have – Lists and Maps. Lists just have values. Maps have keys and values. So if you want the label and the value to be the same, use a List. If you want a different label and value, use a Map, with label in the key and value in the values.

I’m going to start simple with Lists and start at the basic level with core controls. This is also relevant to the Dojo controls like Dojo Filtering Select, Dojo Radio Button. That’s because all these controls take an xp:selectItems complex type as its value. If you’re like me, the most common use case is retrieving values from a field in a keyword document, either from the document itself or from column values – the equivalent of an @DbLookup(). The other most likely use case will be iterating through categories in  a view and outputting category titles – the equivalent of an @DbColumn().

As you’re probably aware, the output of both of the SSJS ways of doing this is an Array. The obvious route I took was looking for a Java class for that. But there is no java.util.Array and this threw me for quite a while when trying to reproduce one-to-one. The good news is you can just pass in an ArrayList<String> or a Vector<String>. For those just starting out on Java, this means an ArrayList or Vector which contains String values. Vector is the stock collection output of Domino objects, whereas ArrayList is the standard basic Java collection object that replaced Vector. You can even use Vector<Object>, although I suspect it will only work if each value is actually a String.

So time for some code:

public Vector<Object> getKeyEnts() {
Database currDb = ExtLibUtil.getCurrentDatabase();
View vwUser = currDb.getView("Keywords");
ViewEntry ent = vwUser.getEntryByKey("ACQUIRED SKILLS", true);
Vector<Object> users = (Vector<Object>) ent.getColumnValues().get(1);
return users;

So we’re going to the Keywords view in the current database, getting the entry with the key “ACQUIRED SKILLS” and returning column 2 (remember the index starts at 0). Then in the XPage, we call it like so:

<xp:comboBox id="comboBox1">

So I’m calling via SSJS the getKeyEnts() method I showed above, which is in my pageController bean. I could streamline the code even further by use ${pagerController.keyEnts} to call the method. The clever bit here is that there is no keyEnts property in my bean. Because value is a property of selectItems, it expects a valueBinding – that is a binding to a Java property rather than a methodBinding which is a binding from an event to a Java method. The valueBinding automatically looks for a method starting get and appending the property, replacing the lower-case first letter with an upper-case. So the getter for keyEnts property will be get + KeyEnts = getKeyEnts().

So Vectors and ArrayLists can automatically be thrown at any selectItems control, whether for a Combo Box, a Radio Button or even a Dojo FilteringSelect. They will give you a list of options in the order the list was populated, where the label and the value are the same.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top