Tag Archives: Java

Left, right, leftback, rightback and replacesubstring in java

I posted some common string functions that I’ve been using alot during the years in @formula, lotusscript (strleft, strright, strrightback, strleftback) and later in SSJS. So I thought that I need them in Java too. There might be some features like the one with dot in the replacesubstring function, feel free to comment so will I fix that 😉

Hope you find it useful.

OpenNTf.org Snippets

IBM Domino and Java problem with old applets

All the old Java applets that is YES in some old apps not yet converted used got another problem today on Domino 9 and 9.01. They are now blocked by Oracle because the code signing certificate is outdated, it seams like when they where updated to work with Java 1.7 45 the person who resigned them did that with an old certificate and now that cert is outdated and has been so for 1 month. If IBM or you want to keep track on when your code or SSL certs expires QNova Systems contract management system works really great for this purpose and many more things, contact me if you want to know more. An interesting thing will also to see if the new code cert created with SHA-2, because I don’t think you can get one with SHA-1 anymore and this will make Java 1.6 outdated because it doesn’t have support for SHA-2.

I’ll keep you updated on this matter.screen392

Evolving the easy XPage keyword bean

The first part of the easy keyword bean can be found here

When working with keywords in XPages your application could greatly take advantage of the possibilities in the XPage Engine. Thru caching of data, What do I mean with caching?

Well today the keyword bean is located in viewScope and that means that it lives only on the current page that is opened. If you move the bean to applicationscope and add some caching functionality we only need to go into the database if the keyword never have been fetched before.

But there is a problem when moving things into applicationscope that is multi user access, and that can easily be solved using synchronization or threadsafe objects.

Another thing is that you need to maintain is keyword updates because they need to be maintained but that is also easy to solve because if you write the Keyword edit save using XPages that you can update the keyword when saving a keyword.

OK so how do we change the code so we get a common applicationscope keyword bean.

first we add a Global CacheObject and next we check against the GlobalCache Object before accessing the database. And we also need a recache option for a certain keyword to get it refreshed when you have saved a keyword.

Let’s Look at some code

we start by importing java.util.concurrent.ConcurrentHashMap and setting up the hasmap object as a cache object. I use the concurrenthashmap to get a threadsafe Cache object in my application scope bean.

We also need to change the object from static to be an ordinary Java object because it will live in the applicationscope. Another thing we also need to implement is serializable if the server want to store the object on disk for any reason.

Let’s move over to the getKeyword function. What we need to do is to check if the keyword is in cache and if it is, return the cached data. If it isn’t found get the data like before and store it in cache and return the data.

And because I call getKeword from the function getKeywordString I only need to change getKeyword when implementing this new functionality.

The last thing we need to add is the recache function, and that one will be a function that clears the data in cache so the next request to get the data will do it from the database.

I almost forgot, we need to change our managebean also and move if from viewScope to Application Scope in the faces-configt.xml file

If you want the full code for this check out this xSnippet on openntf.org

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.

Calling web services from XPages the missing part

I had an XPage project where I needed to call some web services to get some information and after reading on different blogs my hopes of getting this to work was almost null. But sometimes knowing your history helps and I remembered how I started to create subforms using dxl for several years ago and that almost everything is stored with in the design note.

So I started to think, does the built in web service consumer create the code inside the design element and yes it did. Great!

Check out my Notes in 9 video here

or continue to read the post

Is there any common things between between this and XPages, Yes. Java! But there is a problem they work in different jvm:s. But when I looked closer to a web services consumer with generated java code, there where 3 jar files attached to the design note. One with the source, one with the precompiled java code and one with the configuration settings.

Let’s export the java code and try, but there isn’t any way to export it. So I created a Lotusscript agent that will export the consumer code, it can be found at xsnippet.openntf.org or here

Import that code into an agent and place the agent inside your database with the created java web service consumer. Run the agent, enter a valid path for the export.

There is only one thing that you need to check when the consumer is created. The consumer java code must be in a package, if not the XPage code will not work or at least I haven’t found a way.

Now Import the two jar files created, in the XPage jar section, or if you are using 8.5.x add the jar files using the package explorer.

Next step: Create a java file that will use the web service code.

And call the code from the XPage.

No modifying java.policy, No special java command line things the only thing is that you must be able to create the java web service consumer and some web services doesn’t work but that I can live with.

This is of course nothing supported by IBM but I will try to convince IBM to build in the export/import action so my agent is unnecessary.

The sample database can be found here

The databases is using free webservices from http://www.restfulwebservices.net/ where I use the soap version instead for the rest service that is not working with the webservice consumer in Domino.

i.e. the stock quote WDSL file can be found at http://www.restfulwebservices.net/rest/StockQuoteService.svc?wsdl and to be able to use this with Domino I change the url to

http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl to get the soap version of the webservice.

If you have any questions feel free to send me a comment or use the contact link above