Flexibility in applications is always a great thing, to adapt the application to the business needs without recoding things. And if adding this flexibility can be done without lots of code, you will probably use it.
This is one way of creating a keyword data bean for you XPages.
Save the form
Now you need to create the lookup view, create a view called byKeyword
Add 2 columns name and data. The name column should display the name of the Namefield and it must be sorted and the second view should show the data field, Save the new view.
Let move over to the interesting code, create a new java class named FormHelper and place it in a package, I call mine com.xpagedeveloper.
I create two functions, the first one will return return a vector with the data from the keyword.
And my Second function returns string from the array separated with a string of your choice
After I add the bean init setup in the faces-context.xml in the WebContent\WEB-INF folder from the package explorer.
Now it’s very simple to get keyword values to you fields and functions inside your XPages.
Create a Keyword using the Keyword form, in this case I’ve created a Keyword named Category and added some values to it.
And in my XPage I have added an Combobox
And in the values tab click on the “Add Formula Item” button
And write the following code
If you want the full code for the bean, it can be found here as an xSnippet
Now your XPage application is more flexible without lots of code.