XPages custom 404 and error page

This post is about creating a custom error page for handling errors (both controlled errors and not controlled errors) in XPages.

For handling errors in non-XPages requests a non-XPages 404/error page has to be added. To create a custom non-XPages error page, see the Help topic “Custom Web server messages” in Domino Administrator or have a look at this great article by Julian Robichaux on Lotus Domino custom web error pages.

First step for handling errors in XPages requests is to create theΒ  XPage to be used. This XPage can be styled as you wish and you will probably reuse your overall site design – for instance by reusing custom controls that controls the look and feel of your web pages.

To catch controlled errors such as “page not found” errors (to “simulate” a HTTP 404 response) you can use a try/catch statement to redirect to the new XPage in case of “page not found” related errors on your XPage. This can be used to catch errors with data sources where the document id can not be found. The following example code from the documentId part of dominoDocument data source redirects to a custom XPage in case an article id can not be found:

try {
	var tempView:NotesView = database.getView("webpages-by-id");
	var tempDoc:NotesDocument = tempView.getDocumentByKey(param.id);
	return tempDoc.getUniversalID();
} catch(e) {
	context.redirectToPage("error.xsp")
}

The new XPage can also be used instead of the default error page to catch not controlled errors (errors/exceptions in your code). See this article on XPages error management in the Lotus dev wiki. In short, you need to add a computed field that display the value of the request scope variable “error”. The following example code displays the error message in a panel that is only displayed f the scoped variable “error” is present:

<xp:panel id="displayErrors">
	<xp:this.rendered>
		<![CDATA[#{javascript:if (requestScope.containsKey("error")) {
		return true;
		} else {
		return false;
		}}]]>
	</xp:this.rendered>
	<p>
		<b>Description of error:</b>
		<xp:br></xp:br>
		<xp:text escape="true" id="displayError" value="#{requestScope.error}"></xp:text>
	</p>
</xp:panel>

If you want to provide more detailed error messages on this error page, you can add the following computed field:

<xp:text escape="true" id="computedField">
	<xp:this.value>
		<![CDATA[#{javascript:var stackTrace ="";
		var trace = requestScope.error.getStackTrace() ;
		for( var i = 0; i < trace.length; i++){
		stackTrace += trace[i] + '\n';
		}
		return stackTrace;
		}]]>
	</xp:this.value>
</xp:text>

Please consider whether these detailed error messages are something that you would like to present to the users.

A better approach to displaying detailed error messages to your users would be to use logging in your application and then log the detailed error messages and instead present a user friendly error page. Matt White has integrated the OpenLog OpenNTF project with XPages in the TaskJam OpenNTF project. I will definitely have a look at this in the very near future.

XPages cheat sheet

David Leedy has just announced that his XPages cheat sheet will be available for handout at Lotusphere 2011. I can confirm that it is a useful cheat sheet because David involved me in a 2 hour review of the cheat sheet. It was great fun and I am pleased to have been involved in putting the cheat sheet together.

Now I just need someone from the Lotus community to grab me a copy of the handout at Lotusphere that can replace my self-printed copy. Anyone? πŸ™‚

Below is a sneak peek at the cheat sheet courtesy of David Leedy. You will have to wait for Lotusphere 2011 for the real thing:

Update January 21: David has released the XPages cheat sheet a little earlier. Go grab your copy!

Presentation: My view on XPages

I was asked by one of my customers to present my view on XPages and my experience with XPages to their development team. The development team had no experience with XPages but instead with classic Lotus Domino development. I gave the presentation on January 6 and the majority of the presentation consisted of live demos of XPages functionality to show the team how easy it is to use modern web technologies such as Ajax for a Lotus Domino web application.

The presentation is available on Slideshare:

The presentation makes most sense when seen live together with the live demos. Maybe a topic for a video podcast someday? πŸ™‚

Update: Erik Brooks pointed out in the comments that with 8.5.2 it is now possible to call Lotusscript agents from XPages – thereby making reuse of existing backend Lotusscript code possible. The App Dev wiki has more information on the use of Agent.runWithDocumentContext(). I have updated my presentatio on Slideshare to reflect this. Thanks Erik.

HTTP request consumer in XPages

Chris Toohey recently posted an example of a simple HTTP request consumer using a traditional (classic) Lotus Notes/Domino agent. I had a need for a similar solution in XPages – and since Chris never posted his follow-up post on the XPages version I had to do it myself πŸ™‚

The HTTP request consumer is used by a 3rd party callback service to report back the status of (in my case) a HTTP form post submitted earlier by my app to that service.

The XPages solution is a simple XPage that uses the afterRenderResponse event to gather fields returned and display a related response to the user – including displaying a useful error message to the user in case the callback service misses important fields. The HTTP request parameters (form fields) are retrieved using param.get(‘<field>’). The HTTP request parameters can be GET parameters (e.g. http://hostname.com?p1=v1&p2=v2) or POST parameters.

Basic code example for the afterRenderResponse event:

try {

var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
response.setContentType(“text/html”);
writer.write(“” + “\n”);
writer.write(“” + “\n”);
writer.write(“” + “\n”);
writer.write(“” + “\n”);

// Read the HTTP request parameters
var _param1 = param.get( ‘test1’ );
var _param2 = param.get( ‘test2’ );

// then do whatever is needed with the HTTP request parameters – e.g. print the contents of the parameters in the response.
writer.write(“<p>Parameter 1: ” + _param1 + “</p>\n”);
writer.write(“<p>Parameter 2: ” + _param2 + “</p>\n”);

writer.write(“” + “\n”);
writer.write(“” + “\n”);
writer.endDocument();
facesContext.responseComplete();

} catch(e) {

_dump(e);

}

My first two months as self-employed consultant

This is a followup to my first two weeks as self-employed consultant at PHL Consult.

2 months have now passed since I started as full-time consultant at PHL Consult – and I am really enjoying it! It has been exciting to focus on my own business and see the immediate results of actions that I take. I have been in discussions with several potential customers and potential business partners about projects where I can offer my services. Some of these discussions has turned into real work for me and I am happy to say that I now have more than just the one customer I started with 2 months ago. The new customers and new projects are primarily focused around Domino administration (setting up new servers, upgrading existing servers) and around modern web development using XPages.

Almost all of my meetings with new and potential customers have been set up through my social network. This really shows that networking is very important for establishing business contacts. One customer, however, contacted me because they found PHL Consult through a Google AdWords ad when using Google to search for a Lotus Domino consultant. I have set up some Google AdWords ads because Google sent me a free trial of ads for $100. So maybe I should consider using AdWords when my free trial has been spent.

Starting a full-time business also require that I take care of administrative tasks. I have had meetings with my accountant to discuss the structure of my business and have decided to go with a one-man business setup (instead of setting up for instance a limited liability company). I have also talked with insurance companies in order to establish necessary company insurances to cover professional liability and business property such as my IT hardware.

I participated in the 44th DanNotes Lotus user group conference in early November. It was great to meet many of the Danish Lotus customers, Lotus business partners and Lotus consultants. I am also still an active member of the Danish Notesnet group of Lotus specialists.

My first 2 weeks as a self-employed consultant

I started as self-employed full-time consultant on October 18 – and today the first 2 weeks has passed. So how did they go?

I have started working on my first XPages project for my first client. The project is currently in the design and early implementation phase and I have therefore been to a design workshop with Supermouse who is responsible for the information architecture and UI design. I find it very interesting to learn more about XPages and to apply it to a real project.

I was invited as special guest to IBM Hackday 8 at IBM in Copenhagen. It was a fun day with a lot of mobile app discussions including looking at Titanium Appcelerator and how it can be used to develop iPhone and Android applications.

I went to my first all-day Notesnet.dk monthly meeting – and it was nice to meet many of the Notesnet.dk members. I hope to have the opportunity to work with some of my Notesnet.dk colleagues someday on shared projects.

I took part in the recording of episode 24 for one of my favorite podcasts: This Week in Lotus. It was great fun to record the podcast together with Stuart McIntyre, Darren Duke and Joyce Davis.

All in all, I have enjoyed the first 2 weeks as self-employed consultant at PHL Consult.

DanNotes – Danish Lotus User Group – 44th conference

DanNotes logo

The Danish Lotus user group DanNotes is hosting its 44th conference on November 3rd and 4th, 2010.

The agenda consists of IBM and IBM Business Partner presentations on November 3rd and of development and administration tracks on November 4th. The developer track is hosted by Carl Tyler from Epilio while the administration track is hosted by Chris Miller (I do Notes) from Connectria.

I am participating in the conference as a member since PHL Consult is a member of DanNotes. I have created a LinkedIn event for the conference. Will I see you there?

Welcome to the opening of PHL Consult

It’s October 18! Today is my first day as a full time consultant in my own company PHL Consult – where I am going to primarily work with Lotus Notes and Domino based solutions. Feel free to take a look around the new offices πŸ™‚

For my first project for a client I am going to work with XPages. I look forward to the challenge of both learning a lot more about XPages and of implementing the web site for the client.

Let me know if I can provide you with my assistance. Thanks.

Independent member of the Danish Notesnet group

I am pleased to say that my Lotus Notes/Domino consultancy company PHL Consult has been accepted as an independent member of the Danish Notesnet group of Lotus specialists. The members of Notesnet are all self-employed consultants working with Lotus products in general – and for most of the members with Lotus Notes and Lotus Domino in particular. I am sure that being member of this group will benefit me in some way or the other now that I start on my excisting new adventure.

Before being accepted as member I was invited to the group’s September meeting by the chairman of the group John Dalsgaard of Dalsgaard Data. I enjoyed being part of the meeting and now look forward to lots of interesting meetings in the future.

Lotus related podcasts in heavy rotation

Two years ago I blogged about podcasts that I listened to at that moment. Since then lots of new and interesting podcasts have appeared. I currently listen to a lot of Lotus related podcasts and the following are in heavy rotation on my iPhone as they provide me with insight and lots of inspiration:

I see lot of potential in the following podcasts but the authors have been quiet for a while… I hope that they will pick up podcasting any time soon:

Finally I can highly recommend Notes in 9 by David Leedy. David does a great job in teaching XPages using video podcasts. I especially like that he starting from the latest episode (the extended edition episode) now renders the video so that you can watch it on your iPhone and iPad!