XPages Tip: Passing an Array to a Custom Control Property
Custom properties are extremely useful for modular design and reuse by sending custom values into each instance. There are a number of data types that can be selected, but no obvious way to pass an array value. In this post, I’ll describe the issue and how to work around it.
Custom Property Data Types
The default data type for a custom property is
There are a number of primitive data types available in the dropdown:
String Data Type
In this case, I want a property that can accept an array of values.
To test this, I created a simple custom control with two properties,
objectProperty, to test how they handle arrays. They both default to
string as the data type.
You can leave the data type as
string, but compute an array to return. It won’t throw an error, but it will treat it like a single string.
No Data Type
You can remove the data type from the property definition and it won’t throw an error on the custom control. However, that is not a valid property, so its treated as though that property doesn’t exist.
If you’ve already set up an instance of the custom control and passed a value to it, it will throw an error on the custom control instance: Unknown property this.. It is not defined on tag .
Custom Data Type
Fortunately, there’s a really simple solution — you can manually type in a property type.
If you type in
object as the type, it does the trick. (It effectively works as desired, although it actually accepts the data as