XPage Java Tutorial Demo Download

The Demo

My original plan was to put up seperate entries for the final two NotesIn9 videos and say a bit, post the code, and go on and on about stuff that I already mentioned, but as time goes on, and I notice that I am not getting the time to do this as I wanted, the time has come for me to just simply give you the file and let you have fun with it.  This also seems the best option because the code already has the javadoc entries to document everything that I would say in the posts to begin with. Take the nsf, open it up, read the code, and if you have any questions, comments, concerns, please feel free to write to me.  As the readme says, I stand by my work, but I also know that there are a few aspects that could be optimized, and I have in fact optimized a bit in the last few weeks in my productive version.

XPage Java Demo Download

Important Notes

In this version of the Java Utilites, we used the openNTF Domino API M4.5.  This is also the current stand of this Demo.  In the future, this will be upgraded to a new version of the API which eliminate certain bugs in the M4.5 version, such as iterating over empty document collection iterators.

XPage Java dev Tutorial 2 – AdminPanel prt 1


 

General Feels and Gratitude

Hello Everybody!!  Today I am really happy to present my first NotesIn9 video!  It was really great being able to make this sub-series and be a part of the tutorials that really got me going with XPage development.  I want to thank David Leedy for giving me the opportunity as well as thank my employer for allowing me to use what I learn on company time to create content for others.  This is turning out to be a hobby that is really starting to take off.  Again, I have to thank twitter, David Leedy, and Paul Withers for sharing my first blog posts and spreading the word that this blog is out and about.  I would not be so into this right now if it were not for the fresh feeling of being able to do good for others and not just use this website as my own knowledge repository. Thank you to those who read these posts, watch the videos, and of course who retweet, comment and like what I am doing.  All that really makes it easier to stay motivated.


 

Down to Business

What is this mini/sub -series all about?

As you may or may not be aware, everything that we are doing here has a basis in my day to day development.  I started out using java for my xpage dev about a year ago (I had already used java extensively in my daily programming, just not in combination with XPages for which I mostly relied on JavaScript.) To really get started with Java, I decided to make a utility package that included everything that I needed to know to really get going.  I started off with making a sessionHelper.  I did this because I needed to learn how to get a session object.  I did not know anything about the variable resolver at first, and I also had a lot of trouble finding resources to figure it out.  After I managed that, I moved on to one of the most important features of all databases that I develop, the Admin Panel.

The Admin Panel is (currently) a custom control where I store tables that show the variable names and values of all objects located in the applicationScope, the sessionScope, and the viewScope.  I do not waste my time with the requestScope, although I suspect that such a thing would be possible if I found a use case for it.  Additionally to this, I show another HTML table that presents cookie information.  This is a part of another module that I call “the cookie helper”.  Finally, a larger and more complex table presents logging information to the user with a particular role.  The custom control contains functions that erase the variables located in the scoped maps (although I have not made that work without causing errors) add string variables to the scopes (not very helpful, but cool), and delete logging information shown in the debug section of the admin panel.  A great feature of the debug table is that there are six different error levels that all use different row styles.  This allows the trace information to be shown in a more understated way, and fatal errors to pop out like a sore thumb.  Later, I turned this same functionality around to store and show entire session logging documents in a logging database.

Today we are going to look at how to build your own Admin Panel using information built, retained, and retrieved in Java.

How is this sub-series built?

Due to time, I broke this down into three different parts.  Since I am actually coding on camera as much as possible, it is taking a while to get through it.  I am doing this so that you can see where I have difficulty, so that you can hear me commenting as I go, and because my entire concept in this Java Tutorial is to program an application from start to finish together.  When it is just taking too long and when I do not have a lot to say, I do edit out some parts.

Part one (this part) is going to be a basic introduction.  We do, for this one time only, go through a PowerPoint presentation where I go into what we are doing, the three parts, and some basic information about myself.  One thing that changed from the making of the PowerPoint slides to the videos is that the concept had to be changed from asking question before the recording of the next part to all the questions being asked in comments and through email and me answering them in a written format or in a fourth video.  It makes sense for numerous reasons, but we do not need to get into that.

Part two is primarily Java construction.  Although some Java classes were started in the first part, in part two we really get going.  I do not want to spoil it too much here, but we basically finish up all the beans that we are going to need for the custom control.

Part three is being my slight PITA.  I recorded it once already, but am not pleased with how it turned out.  I really need to stop doing my recordings after 1 AM.  I am going to be deleting the changes and redoing the video.  Part three includes registering the beans that we already made with the faces-config.xml file and designing our custom control.  We go into how to add a few custom properties, although we admittedly do not go into every detail that you could possibly go over.  There are numerous NotesIn9s if you need help specifically with Custom Controls.

 Why is this a sub-series?

This is a sub-series because it is a small part in the project that we are building together.  I was trying to find some way to make videos for this page’s main tutorial while also making content for NotesIn9.  I decided that it would be awesome to make some of the content that can really stand alone its own sub series and give them to David Leedy.  For those who follow along here, it should seem pretty seamless.  To those who watch the NotesIn9s, it is my hope that you can watch that content and get what you need without too much knowledge of what we are doing in the rest of the tutorials.  At any rate, I am posting the code on this website.  That being said, without any further ado- I give you the video, and following the video, the code!  Enjoy!


Video

Find the video here!


Code

COMING SOON!

XPage Java dev Tutorial 1

Greetings!!

The time has finally arrived for the first tutorial in XPage Java development.  In this tutorial we will learn how to get a handle on the current session in both the opentNTF Domino API (ODA) and the lotus domino API.  We will briefly go over what we did last time, and we will really hammer out some java code.  Stay tuned for next time when we will actually use Java and Custom controls to log data out to the user/XPage_Admin!!  That tutorial is planned to be given to David Leedy to be shown on NotesIn9!  Please make sure that you take a look at the comments that I added to the code which is displayed below!

Happy Programming!


 


 

package com.reederprogramming.utils;

import java.io.Serializable;

import javax.faces.context.FacesContext;

import org.openntf.domino.utils.Factory;

import com.ibm.xsp.extlib.util.ExtLibUtil;
import com.reederprogramming.exceptions.NullDatabaseException;
import com.reederprogramming.exceptions.NullSessionException;

import lotus.domino.Database;
import lotus.domino.Session;

/**
 * This class is going to contain key methods for dealing with the current session.
 * It implements Serializable in case I want to put this class in the sessionScope later and
 * use from JavaScript as well.  This may not be necessary, but it is easy to implement the interface
 * and take it out later if I need to, or leave it in since it does not hurt anything.
 * Note that all java beans MUST implement Serializable if they are going to be retained in server
 * memory.
 * 
 * @see java.io.Serializable
 * 
 * 
 * @author Greg@reederprogramming.com
 *
 */
public class SessionHelper implements Serializable {

	
	private static final long serialVersionUID = 2014071001L; //yyyyMMdd0v
	
	/**
	 * This is an example of how to get the current database using the utility class provided 
	 * by the Extension Libraries.  Alternatively, you could alter the getCurrentSession() to
	 * return the database.  Alternatively, you could also create an enum that includes all of
	 * valid strings and use that to get the object you desire from the VariableResolver.
	 * 
	 * @return returns an instance of the lotus.domino.Database.
	 * @throws NullDatabaseException thrown when the current database is null.  Should never happen, but
	 * can during multi-threading operations.
	 * @see lotus.domino.Database
	 * com.reederprogramming.exceptions.NullDatabaseException
	 * 
	 */
	public static Database getCurrentDatabase() throws NullDatabaseException{
		Database d  = null;
		d = ExtLibUtil.getCurrentDatabase();
		if(d == null){
			throw new NullDatabaseException("The current database could not be found!");
			/* This is an example of a checked Exception.  It must be handled or else the 
			*  compiler will yell.
			*/
		}
		return d;
	}
	
	/**
	 * This method shows two different examples.  The first one is how to get the 
	 * current session and the current database using the Factory enum provided by ODA
	 * 
	 * @see org.openntf.domino.utils.Factory
	 * @see org.openntf.domino.Database
	 * @see com.reederprogramming.exceptions.NullDatabaseException
	 * @return returns an instance of org.openntf.domino.Database from the ODA.
	 * @throws NullDatabaseException thrown when the current database is null.  Should never happen, but
	 * can during multi-threading operations.
	 * 
	 */
	public static org.openntf.domino.Database getCurrentODADatabase() throws NullDatabaseException{
		org.openntf.domino.Database d = null;
		d = Factory.getSession().getCurrentDatabase();
		if(d == null){
			throw new NullDatabaseException("The current database could not be found!");
		}
		return d;
	}
	
	/**
	 * This method displays a few things.  First off, we see how to check to see if an object is 
	 * the same as another class, and then we perform a cast to a higher level object.  Additionally,
	 * we see how to use the variableResolver to get the session instance.  This will be the same
	 * session object as returned by the session JavaScript keyword variable.
	 * 
	 * We also see an example of the FIX-ME and TO_DO keywords to aide with development processes.
	 * 
	 * @see lotus.domino.Session
	 * @see com.reederprogramming.exceptions.NullSessionException
	 * 
	 * @return returns an instance of the lotus.domino.Session class
	 * @throws NullSessionException
	 */
	public static Session getCurrentSession() throws NullSessionException{
		Object o = null;
		Session s = null;
		
		FacesContext context = FacesContext.getCurrentInstance();
		o = context.getApplication().getVariableResolver().resolveVariable(context, "session");
		if(o instanceof Session){
			s = (Session)o;
		}
		if(s == null){
			//FIXME add logging!!
			//TODO this must be expanded.
			throw new NullSessionException();
		}
		return s;
	}

	/**
	 * This is a similar example to the getCurrentDatabase() where we use the Extension Library utility
	 * class to get a handle on the current session.  This assumes that the Extension library is used
	 * and will always be used.  Becauase this is a class that should always be available, such an
	 * approach may not be wise.
	 * 
	 * @see com.ibm.xsp.extlib.util.ExtLibUtil
	 * @see lotus.domino.Session
	 * @see com.reederprogramming.exceptions.NullSessionException
	 * 
	 * @return returns an instance of the lotus.domino.Session class.
	 * @throws NullSessionException
	 */
	public static Session getCurrentExtLibSession() throws NullSessionException{
		Session s = null;
		s = ExtLibUtil.getCurrentSession();
		if(s == null){
			//FIXME add logging!!
			throw new NullSessionException();
		}
		return s;
	}
	
	/**
	 * This method illustrates how to get a handle on the current session using ODA.  This is only
	 * one possible way.  Furthermore, it shows how to wrap a normal lotus.domino object (they will always extend
	 * lotus.domino.Base) and return an ODA object.  According to one of the authors (Paul Withers), 
	 * it is however preferable to use the Factory.getSession() method.
	 * 
	 * @see org.openntf.domino.Session
	 * @see com.reederprogramming.exceptions.NullSessionException
	 * @see org.openntf.domino.utils.Factory
	 * 
	 * @return returns an instance of org.openntf.domino.Session
	 * @throws NullSessionException
	 */
	public static org.openntf.domino.Session getCurrentODASession() throws NullSessionException{
		/* 
		 * if you look at the above method declaration, you will notice that I am 
		 * specifying which Session object should be returned.  This is done because other
		 * methods in this class work with the lotus.domino.Session class. I must insert the full
		 * name (including package) in order to prevent ambiguity.  I can, however, debate if
		 * either of them should be imported, or which one makes more sense to import.
		 */
		
		//TODO change this method to simply use the getSession()  This is only for the sake of example
		org.openntf.domino.Session s = null;
		s = Factory.fromLotus(getCurrentSession(), org.openntf.domino.Session.class, null); 
	   
		/* 
		 * normally we would have to catch the NullSessionException given by the getCurrentSession().
		 * in this case, it just makes more sense for it to bubble up to the next method and let it deal with it.
		 */
		if(s == null){
			//FIXME add logging!!
			throw new NullSessionException("Missing session of type: " + org.openntf.domino.Session.class);
		}
		
		return s;
	}
}

 

package com.reederprogramming.exceptions;

/**
 * This is an Exception class to mark that a session object could not be returned.
 * It can be used for ODA or for lotus.
 * 
 * @author greg@reederprogramming.com
 */
public class NullSessionException extends Exception {
	
	private static final long serialVersionUID = 2014071001L; //yyyyMMdd0v

	public NullSessionException() {
	}

	public NullSessionException(String arg0) {
		super(arg0);
	}

	public NullSessionException(Throwable arg0) {
		super(arg0);
	}

	public NullSessionException(String arg0, Throwable arg1) {
		super(arg0, arg1);
	}

}

 

package com.reederprogramming.exceptions;

/**
 * This is an Exception class to mark that a Database object could not be returned.
 * It can be used for ODA or for lotus.
 * 
 * @author greg@reederprogramming.com
 */
public class NullDatabaseException extends Exception {
	
	private static final long serialVersionUID = 2014071001L; //yyyyMMdd0v

	public NullDatabaseException() {
		super();
	}

	public NullDatabaseException(String arg0) {
		super(arg0);
	}

	public NullDatabaseException(String arg0, Throwable arg1) {
		super(arg0, arg1);
	}

	public NullDatabaseException(Throwable arg0) {
		super(arg0);
	}

}




Intro to the XPage Java dev Tutorials

It is finally on its way!

In February or March I decided that I want to start a tutorial series on XPage development and really share what I have been able to figure out this past year or so.  As I have said numerous times, I am a big fan of Java and think it is very important for every serious XPage developer to know.  I spent a great deal of time setting up an environment at home to be able to do this.  It includes a domain controller (samba) running on an Ubuntu Linux Server, Domino running on windows 7, and a client also running on windows 7.  I do a short intro in the video.

I want to do these tutorials differently from those that I have seen so far.  I do not want to just write a class and say, here use it, but rather go into a “real” project, or better a project that could be real.  It is not enough for me to just show a few snippets and say have fun with it, I want to build something that can be used so that we also hit real world problems.  I am not going to sugar coat the videos and edit out every little mistake and plan out every line that I am going to write…. I have an idea of what I want to accomplish, mistakes be damned.  My mistakes can help you learn as well as show that we are all human.

In this video, we will be giving a quick intro to the environment, take a brief look at the server documents and groups that I set up, and most importantly install the extension libraries and openNTF Domino API.  (May I please just call it ODA?)  We install them both onto the server and onto designer.  Please keep in mind that this video also serves as a test for me so that I know that the software I am using actually plays in the quality that I am going for.  So without further ado, enjoy the video!


Just a quick note, I am really annoyed with the video quality.  The good news is that the source video is much nicer.  I am going to have to go through and re-edit it with better software.  At least it is the intro video / ExtLibs installation video and not the project kickoff.  Also, do not be too disturbed by the first linux part and the small window.  The windows stuff is displayed full sized.