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.

  1. 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

    • Fredrik Norling

      Absolutly, that’s a great way to do it. There is a followup article coming showing how to add caching to the bean.
      And perhaps if the keyword starts with Global_ it is featched from the common database and in other cases locally 🙂
      The possibilities are endless.

  2. Steven Podrouzek

    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

  3. Sachin Kulkarni

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

  4. 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.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

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