Posts Tagged ‘java’

10 Jul 2013

XPages Video Tutorial: Signing a Notes Database using Java

In this video tutorial I show you how to sign a Notes Database using the Server’s ID via Java Code.

In Lotus Notes version 6, IBM introduced a new method for the NotesDatabase Object called “sign()”. this allowed you to sign either the current database or another database using your current Notes ID. The only issue with this is that the Sign Request would only work if triggered manually inside the Notes Client.

For XPages development, this becomes an issue because you cannot perform a NotesDatabase.sign() on the front-end of your XPages Application.

So without further adieu, here’s the Video :)


5 Jun 2013

XPages Java Tip: Be careful with static variables in your Classes

I learned a very valuable lesson the other day when I relied on the Java Editor to recommend the setting of certain members in my classes. This is a silly mistake that occurred and only cost me about 1.5 hours of troubleshooting, but hopefully others can learn from this and not make the same mistake.


I need to thank the following 4 individuals for assisting me with this issue:

1. Serdar Başeğmez – (Who pretty much knew what the issue was but I didn’t understand him properly. Sorry man)

2. Solly Bronkhorst - (My senior Domino Developer at Ukuvuma, who is quite new to Java, but managed to point out the issue fairly quickly. That’s mad skills Solly)

3. Thimo Jansen - (For really trying hard to help me out. I really appreciate the effort Thimo)

4. Paul Withers – (For providing me an alternative to the below issue in Java. Thanks man)

5. John Dalsgaard and Nathan T Freeman – (For providing valuable feedback on my Blog Post and helping me correct some of my statements which were quite misleading)


In my XPages Applications, my Application Logic is designed around the MVC Architecture. For every Application I usually create a “Global Controller” Java class that initializes certain parts of my application and sets a few members. I access the Global Controller via a managed Bean which I store as a Session Scope Object (Session Scope meaning the Object will remain active for the current Notes Database/Application for the current User only).

Inside this Global Controller, I have a few member properties that get populated on load of the application. (e.g. The current Username, e-mail address, roles, etc). In one of my cases these members needed to be used in my XPages as well as in some of my other Java Classes.


While I understood how to get a handle on my Managed Bean via my XPages and Custom Controls, I made an assumption on how to get a handle on it in my other Java Objects. I would import the “Global Controller” into my Java Class and reference its members directly.

Everything worked fine for me when I was testing the application, but the moment there was more than 1 user working in the Application, my Global Controller’s members would be overwritten (i.e the username is not mine, but the 2nd user’s. The same for the roles, e-mail address, etc).

It was as if my Global Controller was being stored as an Application Scope Object and not a Session Scope Object.


When I imported my Global Controller into my other Java Objects and started referencing its member properties, the Java editor started returning errors, telling me that my Global Controller’s members need to be Static. It was here that I allowed the Java Editor to make the necessary changes in my code.

So what does it mean to have a static member? From my understanding, Static members are initialized only once and at the start of the execution. When I launched my XPages Application, my static members would be initialized and would then be stored as values to be used by everyone until they were re-initialized. So if I launched the application first (me as John Jardin), the member properties would be populated with my details, which is correct. If a second user launched the application on her side (Susan Smith), the member properties would be changed and would contain her details. This directly affects me and any user who launched the Application prior to Susan.


You cannot import a Java Object into another Java Object and assume to get a handle on it the same way you would in XPages via a Managed Bean. At least this is how I understand it. What you need to do in your Java Object is get a direct handle to your Managed Bean, which contains an Instance of your Global Controller.

Let’s say that your facesconfig.xml has the following code that defines your Managed Bean:


To use this Managed Bean in your Java Object, you’ll need the following code:

FacesContext context = FacesContext.getCurrentInstance();
GlobalObject globals = (GlobalObject) context.getApplication().getVariableResolver().resolveVariable(context,"GlobalObject");

Here you created a variable called “globals” and connected it to your GlobalObject Managed Bean. Now you can continue working with your Global Object in your Java Class. Simple as that.

Till next time. Cheers
14 Jan 2013

My Take on Notes/Domino 9 Development – Part 1

Hi everyone. Since the launch of Notes/Domino 9 Beta last year December, I decided to start one of my Projects using Domino Designer 9. One would call this quite risky, but I must say that I’ve never struggled with Beta or First Releases of IBM Notes Software.

To make matters more risky, the Project I started involves the following technologies over and above XPages and very basic Dojo functionality:

jQuery 1.8 Client Side Development (Mark Roden. Stop smiling already)

Twitter Bootstrap Framework replacing OneUI Theme. (That goes for you too Team)

– All my business Logic is written in Java as opposed to Server Side JavaScript (This is my first Project where all logic is Java Based)

– The Application’s Design is based on MVC Architecture. (All my Models and Controllers are managed in Java. No Data Sources, no SSJS)


Java Coding and Debugging

The good news is that I got the Java Debugger running the first time, although it returns a dodgy message that it cannot connect to the server if you try to start it up when it’s already running. The Java Debugger is a touch different from the LotusScript Debugger, but it definitely has more features. I just need to get more used to it and understand how it works.

Java coding is actually a pleasure once I started understanding Java Coding Concepts. The Editor is very friendly and does a lot of the work for you. It will be quite tough for me to go back to coding Business Logic in SSJS.

with most of my Logic sitting in SSJS in previous projects, It’s difficult to compare XPages Java Development in Domino Designer 9 vs 8.5, but I can definitely confirm that it’s responsive, friendly and a pleasure all in all.


XPages and Custom Controls

Many of the issues I faced day to day seemed to have disappeared. Stuff like not being able to drag custom controls into the Source or Design View if your XPage  has been open for a while. The Intelli-sense in the Source View also makes developing directly in the Source View friendlier, which is good news for those who still work in the Design View and want to make a change.

The Design Builds are also a pleasure. I’ve rarely used the “Project Clean and Build”, even when adding new design elements.



In short, so far I am very happy. The Domino Designer 9 is a touch faster than 8.5 and is very stable. I forget that I’m working in a Beta Client.

As far as my current Project goes, I’ve mingled with pretty much everything that I would need for my Application, so I’m not expecting many surprises before I complete Phase 1.

I would love to get feedback from others and their experience so far developing in Domino Designer 9 Beta.


Cheers for now


28 Aug 2012

Important Tip when comparing values in Java

Hi everyone. Here’s a quick post that might save you a lot of time. With some programming languages like JavaScript, @Formula or LotusScript, to compare a String value is pretty simple

@Formula: tmp1 := “Test”;

tmp2 := “Test”;

(tmp1 = tmp2) = True

JavaScript:var tmp1 = “Test”;

var tmp2 = “Test”;

(tmp1 == tmp2) = True


LotusScript:dim tmp1 as String

dim tmp2 as Stringtmp1 = “Test”

tmp2 = “Test”

if(tmp1 = tmp2) = True


But when it comes to Java, the rules are slightly different:

String tmp1 = “Test”;

String tmp2 = “Other Test”;

(tmp1 == tmp2) = True


In Java, the == operator compares Objects and not the physical values contained within. The line above this is checking if the object tmp1 is the same object as tmp2.

So, in Java, the proper way to compare values is by using the equals() method:

String tmp1 = “Test”;

String tmp2 = “Test”;

(tmp1.equals(tmp2) = True


If it’s anything that I can teach you today, it’s that with Java almost everything is an Object and not just a data type. If it’s an Object, it has Properties and Methods that should be considered at all times, especially when parsing or comparing values.

Cheers for now :)


25 Jul 2012

XPages Tip: Determine the Object Type of your Scoped Variable in Java

Hi All. I’m still relatively new to Java, so I landed up in a scenario where I thought my object was a Vector, but it was actually a String Object.

This cost me some time as I was trying to pass the Scoped Variable into one of my existing Vector Objects. I had checks to see if the Scoped Variable was null or blank, but I needed a check to see if it was in fact a Vector or just a String.

It’s the old problem of if you only have 1 value, then it’s a String, and when you start having more than 1, it’s an Array.

So in Java, when faced with this problem, you can use the .getClass() and .getName() method to check what you actually have.

The example below shows how I used this. I’m sure there’s a much better ways of doing this check, but for now, it works.

Cheers all.



Vector myarray = new Vector();

if (viewScope.get(“ScopeName”).getClass().getName().equals(“java.lang.String”))

     //It’s a String value, not an Array


} else {

     //It’s an Array. Yippee!!

     myarray = (Vector) viewScope.get(“ScopeName”);



Thanks to Tommy Valand, below is another example of how to achieve this (See Red Text below). It’s also noted that the below method is preferred to what I show above.

Thanks Tommy for your feedback.


Vector myarray = new Vector();

if (viewScope.get(“ScopeName”) instanceof String)

     //It’s a String value, not an Array


} else {

     //It’s an Array. Yippee!!

     myarray = (Vector) viewScope.get(“ScopeName”);