Creating an easy XPage keyword bean

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.

Start by creating a form named Keyword, in this form add the fields Name and Data, add the multivalue checkbox in the datafield question079

 

 

 

Save the form

Now you need to create the lookup view, create a view called byKeyword

question080

 

 

 

 

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.

question081

 

 

 

 

 

 

 

 

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.

Snap2

 

 

 

And in my XPage I have added an Combobox

question094

 

 

 

 

 

 

 

 

And in the values tab click on the “Add Formula Item” button

question095

 

 

 

 

 

 

 

And write the following code

question096

question097

 

 

 

 

 

 

 

 
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.

Leave a Reply

6 Comments on "Creating an easy XPage keyword bean"

Notify of
avatar
Sort by:   newest | oldest | most voted
Don Mottolo
Guest

Fredrik,

Nicely done and thanks for sharing this! You now have me thinking that this could be used in a central database for keywords that are not application specific (and are used in many applications). For example: lists of states or countries. Any thoughts / recommendations?

Don

Steven Podrouzek
Guest

Hey Fredrik. This is very well explained and so easy. What I like is the practical aspect of what you showed. We all need a keywords database. I was getting tired of the @DBColumns and @DBlookups. I’m sure that this way is even quicker on the server. Thanks

Sachin Kulkarni
Guest

Amazing way of referencing keywords, which we use in all applications. Very helpful. Thanks for sharing

Mark Maden
Guest

Hi Fredrik,
I am just starting to learn Java in XPages, (no idea why, yet!) so some of the above Java is beyond me at this stage, but this is so professionally produced, – unlike many well intended articles, – you can follow every step of the process regardless of whether you are an expert or a novice like me.

Thank you.

wpDiscuz