XPages: Taking The Next Step
A common theme in my blogs about XPages has been the challenges that come in learning how to develop XPages. I have made numerous remarks about the on-line documentation and the importance of community contributions to fill that void. If you or your company has the money there are also some excellent resources such as the TLC courses on XPages and JavaScript. There are also a great many books on JavaScript and Dojo that are immense value for learning some key aspects of XPages. These are all great to get you started.
At the end of the day there is no substitute for sitting down and writing an XPage application. My suggestion here is not merely to start building something based upon what XPages can do. (A solution in search of a problem). It is often better to start with a specific need and then meet and confront the challenges of implementing that problem using XPages. This is how I have started to get a more solid understanding of XPages and how it can be applied to what I am called upon the do as a Notes developer. This usually leads to a solution. Not necessarily a great solution. It is unlikely to be the sort of code you would hope to be writing in a few years time, or even your next XPages project! But it is an important start.
So what comes next? If you are like me and have been programming in Notes for a while it may feel like your first XPage application has been written using crayons. As a professional developer you need to quickly develop a kitbag of acceptable best practice for XPages so you can start copying code from application into another with confidence the code is well written, robust, and efficient. So how do you take those first applications scrawled in crayon and turn them into masterpieces? To take that next step I look to the gurus in the field and then try and observe very closely what they do and how they do it. Everyone will have there own views who the XPage gurus are. I am reluctant to mention any in case I offend those I forget to mention. But the people on my short-list include my fellow bloggers here at The XPages Blog plus Tim Tripconny and Nathan Freeman et al at Lotus911. Not all these people are providing free access to all the XPage applications they are building but you can:-
- Read their blogs and look closely at the code examples. The comments often provide as much insight as the blog;
- View applications they have built that are available on-line; and
- View their contributions on OpenNTF.
Applications to look at closely include:-
- IQJam - Probably the most sophisticated and impressive application I have seen so far built using Xpages. This is a commercial product but you can probably get some idea how it is built by looking at the code Elguji have posted for TaskJam.
- XTalk - So you've all read the 54 part series on learning Xpages. Now take a look at what Declan finally developed with this great example of an XPage application Declan has kindly added as an OpenNTF project.
- XPages Wiki - Steve Castledine and Niklas Hedloff are two of IBM's leading application developers and this OpenNTF project provides some insight into how IBM code Xpage applications.
- XPages Framework - Another contribution from Steve & Niklas at IBM worth a close look.
Please feel free to add to this list with comments
Look closely at the code in these projects and compare them with your own. Look for ideas on how you can refactor your code to better implement best practice. Once you have done this you will have a much sounder base from which to build project #2, #3, #4, ....
Note: If you are keen to get your hands dirty with XPages but your employer does not have enough (any?) XPage projects for you to work on, you should seriously consider getting involved with one or more OpenNTF projects. If you are presently "between contracts" or even "between jobs" it is probably even more important as a way to bolster your resume with a skill that is still in short supply. Discussion NextGen is a perfect example of a project with an XPage component in which you can not only get your feet wet, but you will also be working directly with IBM.
Prototype versus Closure in SSJS
JavaScript is an Object-Oriented programming language. While languages such as LotusScript, Java, and C# use classes, Javascript (including SSJS) uses objects in a form of OOP known as Prototype-based programming. Inheritance is one of the key features of OOP. There are two techniques that can be used to implement Inheritance within JavaScript. These are commonly known as Closure and Prototype. Both techniques construct objects by defining a function and then assigning the function to a variable using the new statement. Where these techniques differ is the process by which Inheritance is implemented to add properties/methods.
Note: At this time properties are not supported in JavaScript and are typically supported by creating a pair of get and set methods.
Closure
With Closure methods are defined inside the parent object.
// Cartesian Coordinates - Closure implementation
function CartesianC(x, y)
{
this.x = x;
this.y = y; }
this.getX = function()
{
return this.x;
}
}
Closures allow a developer to define all the methods up front in much the same way that classes are typically built.
Prototype
In contrast, prototyping adds methods using the special prototype statement to effectively extend the existing object.
// Cartesian Coordinates - Prototype implementation
function CartesianP(x, y)
{
this.x = x;
this.y = y;
}
CartesianP.prototype.getX = function()
{
return this.x;
}
Prototype maximizes the flexibilty of JavaScript making it possible to add additonal methods at any stage.
Closure versus Prototype
Given there are two ways to implement inheritance, which one should we use? Well in client-sided Javascript it is generally held that Prototype is the superior choice. While I have heard some people suggest that prototype is a "hack", it is in fact the default way to implement inheritence and is described in the ECMAScript standard. There has been a lot written on the subject and most people seem to side with Prototype. The reasons include:- the code runs faster; consumes less memory; and the objects are more easily extended.
In contrast there is little written so far on the topic for SSJS. Given the SSJS code is implemented a little differently I decided to do a few tests to compare the performance of the two options. If you visit my Web site at www.dominoframework.com and look under "XPages Kindergarten" you will find an entry for Closure v Prototype (note: There are issues with ie and digit trees so use a decent browser!). Here you can test the code out yourself. The results were somewhat inconclusive.
The bottom line is that there is perhaps no compelling reason to use one over the other. It most likely comes down to personal preference. Despite this, I am presently siding with Prototype within my own xDomino Framework. The key reason being it matches the style of the JavaScript language. The key strength of JavaScript is the flexibility of the language. That is part of the reason I see it as such a good fit for Lotus Notes. Implementing inherence through Prototype magnifies flexibility.
Note: There is at least one compelling reason to use Closures within SSJS. At present the SSJS Editor in DDE does not recognize the prototype statement for what it is and hence the methods it creates do not show up in the outline as methods of the parent object. This makes navigation of SSJS the same nightmare LotusScript was prior to ELSE (EclipseLotuSScript Editor).
XPages heading to New York City!
In New York City, on November 9th, I'll be at the Tri State Lotus User Group presenting a session on XPages.
Xpages: After the Introduction
You've heard about XPages and maybe even read a blog post or two, but where do you really start? Why dip you're toe in the water when you can dive right in? This session will help you establish a comfort zone with XPages. See how to take your existing knowledge of the Notes Client to the next level. Demos allow you to walk through an application that uses Type Aheads, Validation, Repeat controls and more! See how to achieve good functionality with relatively little code to write - just don't tell your boss!
If you like any of my Notes in 9 screencasts you'll hopefully get a feel for what to expect. I like to think of that is "Notes in 9 - Live and in person!".
The great thing about the day, is that there's something for everyone. Check out the fantastic Agenda!
Hope to see you there!