Archives for the ‘XPages’ Category

5 Jun 2013
4

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.

WHO TO THANK

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)

LET ME ADD SOME CONTEXT

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.

WHAT WAS THE PROBLEM?

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.

WHY DID IT HAPPEN?

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.

RESOLUTION

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:

<managed-bean>
    <managed-bean-name>GlobalObject</managed-bean-name>
    <managed-bean-class>com.ukuvuma.designmanager.globals.GlobalObject</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</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
John
23 Jan 2013
0

Join me at IBM Connect to discuss XPages and Appcelerator Titanium

Good day everyone.

I am glad to announce that whilst I will not be presenting at IBM Connect this year, I will be hosting a “Birds of a Feather” (BOF) session on Tuesday morning at 7:00am. The Session’s name is “BOF206 IBM XPages and Appcelerator – A Marriage Made in the Clouds” and will be held at the Swan Hotel.

So the difference between an IBM Connect Presentation and a BOF Session is pretty simple:
A BOF Session is similar to a “Round Table” or “Chalk Board” meeting, where everyone attending gets to join in and voice their opinions, ideas and concerns around the Session’s Topic. I must say I do prefer this type of set up because I get to engage with the audience.

Below is the Session’s Agenda:

Web Applications vs Native Applications

I explain the difference between Mobile Web Apps and Mobile Native Applications, as well as their pros and cons.

Technologies and Frameworks used to create Mobile Web Applications

I talk about the JavaScript Frameworks used to create Mobile Web Applications including Dojo, jQuery Mobile, Sencha Touch, Twitter Bootstrap, etc.

Skills required to create Mobile Native Applications

I give a quick overview of what is required to create Native Mobile Applications for Android, Apple, Blackberry and Windows Mobile.

What is Appcelerator Titanium

Here I give an overview of how Appcelerator Titanium works and the features that it offers.

Appcelerator Titanium vs other Mobile Native Wrappers

I compare Appcelerator Titanium to other Mobile Native Wrappers like Phonegap, Corona, etc.

Integrating Appcelerator Titanium with XPages

I explain how to create XAgents in XPages which will be used to receive data from Appcelerator Titanium, process the Business Logic and send data back.

Creating a mobile strategy that works

In this final Topic, I bring together everything mentioned above  and discuss the choices I made and the Technologies I decided to use to implement a Mobile Development Strategy for businesses.

My goal with this Agenda is to share my past year’s experience and discuss Appcelerator and other complimenting technologies, which will assist in providing a way forward for hopefully all who attend.

Hope to see you there :)

17 Jan 2013
2

XPages Tip: Pass NotesDateTime to the Javascript Date Object

Hi all.

I spent this morning creating a massive SSJS Validation Rule that had to do with Date and Time values that were provided by the User online. I think Date Objects will forever remain my Everest, because I just can’t seem to get it right without wasting hours on it.

In SSJS, the problem with the NotesDateTime Object is that properties like “getDateOnly”, “getTimeOnly” and “getLocalTime” return the values as strings. If you want to compare values, you’re in for a tough time.

Now the Javascript Date Object offers you way more in terms of comparing values. Click here to check an awesome function you can use in your code.

I had a scenario where I was using NotesDateTime Objects to manipulate Date/Time Values, but I wanted to pass these Date/Time Values to the JavaScript Date Object to perform compares, etc. My first attempt failed when I tried to use the “getLocalTime” property of the NotesDateTimeObject:

Note: This example is not best practice, but allows me to show you a function available in SSJS

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.getLocalTime());

The above-mentioned will fail because date1.getLocalTime() is an illegal Date value according to the JavaScript Date Object. Having said that, there is an awesome NotesDateTime Method called .toJavaData() that converts the value to a JavaScript Date Object:

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.toJavaDate());

From here use you can use the Date Object for comparing Date and Time Values.

I trust this helps :)

John.

15 Jan 2013
0

DDE9 XPages Tip: De-compress CSS and Dojo Resources for troubleshooting

Hi all. So the other day Dojo 1.8 in DDE9 was giving me a bit of grief. Thanks to a neat feature in Notes/Domino 9 I managed to find out why it was complaining.

So the Dojo Library that gets loaded for your XPages Application is minified. This means that when you receive a Dojo error and want to check what it’s moaning about, it’s nearly impossible due to all the Dojo JS code been compressed to 1 line. See below:

 

Notice that line 15 contains all the Dojo Code in the dojo.js File. Thanks to DDE9, there’s a different way that really helps. Do the following:

1. In DDE9, open up your Application’s XSP Properties, which you will find under “Application Configuration“.

2. Navigate to the Persistance Tab.

3. Select the “Use uncompressed resource files (CSS & Dojo)“.

4. Rebuild your Application.

 

If you refresh your XPage in let’s say Firefox, you should now see the following in Firebug:

 

Simple enough, don’t you think?

Hope this helps.

Cheers.

 

14 Jan 2013
13

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 CollaborationToday.info 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.

 

Summary

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

John.